From: Philip Homburg Date: Mon, 11 Jul 2005 13:02:59 +0000 (+0000) Subject: Select patches for TCP read and write. TCP support for FIONREAD. X-Git-Tag: v3.1.0~631 X-Git-Url: http://zhaoyanbai.com/repos/doc/tz-art.htm?a=commitdiff_plain;h=c60f3ff846f1212ee1213a80f6c73223090e6afe;p=minix.git Select patches for TCP read and write. TCP support for FIONREAD. --- diff --git a/servers/inet/generic/tcp.c b/servers/inet/generic/tcp.c index 2add222fe..8c64d0893 100644 --- a/servers/inet/generic/tcp.c +++ b/servers/inet/generic/tcp.c @@ -706,8 +706,8 @@ ioreq_t req; 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]; @@ -833,6 +833,17 @@ assert (conf_acc->acc_length == sizeof(*tcp_conf)); 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); diff --git a/servers/inet/generic/tcp_int.h b/servers/inet/generic/tcp_int.h index 8d6f47987..154c653a4 100644 --- a/servers/inet/generic/tcp_int.h +++ b/servers/inet/generic/tcp_int.h @@ -192,6 +192,7 @@ void tcp_frag2conn ARGS(( tcp_conn_t *tcp_conn, ip_hdr_t *ip_hdr, 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 )); diff --git a/servers/inet/generic/tcp_recv.c b/servers/inet/generic/tcp_recv.c index 0a510bee4..b009b0a4e 100644 --- a/servers/inet/generic/tcp_recv.c +++ b/servers/inet/generic/tcp_recv.c @@ -1442,6 +1442,44 @@ tcp_conn_t *tcp_conn; 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 $ */ diff --git a/servers/inet/inet.h b/servers/inet/inet.h index 0b1ace85e..3d99d7c08 100644 --- a/servers/inet/inet.h +++ b/servers/inet/inet.h @@ -26,6 +26,7 @@ Copyright 1995 Philip Homburg #else /* Assume at least Minix 3.x */ #include +#include #include #include #include