tcp_conn_t *tcp_conn;
nwio_tcpconf_t *tcp_conf;
nwio_tcpopt_t *tcp_opt;
- acc_t *conf_acc, *opt_acc;
- int result;
+ acc_t *acc, *conf_acc, *opt_acc;
+ int result, *bytesp;
tcp_fd= &tcp_fd_table[fd];
reply_thr_get (tcp_fd, NW_OK, TRUE);
result= NW_OK;
break;
+ case FIONREAD:
+ acc= bf_memreq(sizeof(*bytesp));
+ bytesp= (int *)ptr2acc_data(acc);
+ tcp_bytesavailable(tcp_fd, bytesp);
+ result= (*tcp_fd->tf_put_userdata)(tcp_fd->tf_srfd,
+ 0, acc, TRUE);
+ tcp_fd->tf_flags &= ~TFF_IOCTL_IP;
+ reply_thr_put(tcp_fd, result, TRUE);
+ result= NW_OK;
+ break;
+
default:
tcp_fd->tf_flags &= ~TFF_IOCTL_IP;
reply_thr_get(tcp_fd, EBADIOCTL, TRUE);
void tcp_fd_read ARGS(( tcp_conn_t *tcp_conn, int enq ));
unsigned tcp_sel_read ARGS(( tcp_conn_t *tcp_conn ));
void tcp_rsel_read ARGS(( tcp_conn_t *tcp_conn ));
+void tcp_bytesavailable ARGS(( tcp_fd_t *tcp_fd, int *bytesp ));
/* tcp_send.c */
void tcp_conn_write ARGS(( tcp_conn_t *tcp_conn, int enq ));
printf("tcp_rsel_read: no select_res\n");
}
+PUBLIC void tcp_bytesavailable(tcp_fd, bytesp)
+tcp_fd_t *tcp_fd;
+int *bytesp;
+{
+ tcp_conn_t *tcp_conn;
+ size_t data_size, read_size;
+ acc_t *data;
+ int fin_recv, urg, push, result;
+ i32_t old_window, new_window;
+ u16_t mss;
+
+ *bytesp= 0; /* The default is that nothing is available */
+
+ if (!(tcp_fd->tf_flags & TFF_CONNECTED))
+ return;
+ tcp_conn= tcp_fd->tf_conn;
+
+ if (tcp_conn->tc_state == TCS_CLOSED)
+ return;
+
+ urg= tcp_Gmod4G(tcp_conn->tc_RCV_UP, tcp_conn->tc_RCV_LO);
+ push= (tcp_conn->tc_flags & TCF_RCV_PUSH);
+ fin_recv= (tcp_conn->tc_flags & TCF_FIN_RECV);
+
+ data_size= tcp_conn->tc_RCV_NXT-tcp_conn->tc_RCV_LO;
+ if (fin_recv)
+ data_size--;
+ if (urg)
+ data_size= tcp_conn->tc_RCV_UP-tcp_conn->tc_RCV_LO;
+
+ if (urg && !(tcp_fd->tf_flags & TFF_RECV_URG))
+ return;
+ else if (!urg && (tcp_fd->tf_flags & TFF_RECV_URG))
+ return;
+
+ *bytesp= data_size;
+}
+
/*
* $PchId: tcp_recv.c,v 1.30 2005/06/28 14:21:35 philip Exp $
*/
#else /* Assume at least Minix 3.x */
#include <unistd.h>
+#include <sys/ioc_file.h>
#include <sys/time.h>
#include <minix/config.h>
#include <minix/type.h>