Changeset 2a3214e in mainline for uspace/srv/net/tl/tcp/conn.c
- Timestamp:
- 2011-10-26T16:50:52Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8218b6b
- Parents:
- 6e88fea
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/conn.c
r6e88fea r2a3214e 45 45 #include "segment.h" 46 46 #include "seq_no.h" 47 #include "state.h" 47 48 #include "tcp_type.h" 48 49 #include "tqueue.h" … … 51 52 #define SND_BUF_SIZE 4096 52 53 54 #define MAX_SEGMENT_LIFETIME (15*1000*1000) //(2*60*1000*1000) 55 #define TIME_WAIT_TIMEOUT (2*MAX_SEGMENT_LIFETIME) 56 53 57 LIST_INITIALIZE(conn_list); 54 58 55 59 static void tcp_conn_seg_process(tcp_conn_t *conn, tcp_segment_t *seg); 60 static void tcp_conn_tw_timer_set(tcp_conn_t *conn); 56 61 57 62 /** Create new segment structure. … … 63 68 tcp_conn_t *tcp_conn_new(tcp_sock_t *lsock, tcp_sock_t *fsock) 64 69 { 65 tcp_conn_t *conn ;70 tcp_conn_t *conn = NULL; 66 71 67 72 /* Allocate connection structure */ 68 73 conn = calloc(1, sizeof(tcp_conn_t)); 69 74 if (conn == NULL) 70 return NULL; 75 goto error; 76 77 conn->tw_timer = fibril_timer_create(); 78 if (conn->tw_timer == NULL) 79 goto error; 71 80 72 81 /* Allocate receive buffer */ … … 78 87 79 88 conn->rcv_buf = calloc(1, conn->rcv_buf_size); 80 if (conn->rcv_buf == NULL) { 81 free(conn); 82 return NULL; 83 } 89 if (conn->rcv_buf == NULL) 90 goto error; 84 91 85 92 /** Allocate send buffer */ … … 88 95 conn->snd_buf_fin = false; 89 96 conn->snd_buf = calloc(1, conn->snd_buf_size); 90 if (conn->snd_buf == NULL) { 91 free(conn); 92 return NULL; 93 } 97 if (conn->snd_buf == NULL) 98 goto error; 94 99 95 100 /* Set up receive window. */ … … 109 114 110 115 return conn; 116 117 error: 118 if (conn != NULL && conn->rcv_buf != NULL) 119 free(conn->rcv_buf); 120 if (conn != NULL && conn->snd_buf != NULL) 121 free(conn->snd_buf); 122 if (conn != NULL && conn->tw_timer != NULL) 123 fibril_timer_destroy(conn->tw_timer); 124 if (conn != NULL) 125 free(conn); 126 127 return NULL; 111 128 } 112 129 … … 803 820 log_msg(LVL_DEBUG, "FIN received -> Time-Wait"); 804 821 conn->cstate = st_time_wait; 805 /* XXX start time-wait timer */ 822 /* Start the Time-Wait timer */ 823 tcp_conn_tw_timer_set(conn); 806 824 break; 807 825 case st_close_wait: … … 811 829 break; 812 830 case st_time_wait: 813 /* XXX Restart the 2 MSL time-wait timeout */ 831 /* Restart the Time-Wait timer */ 832 tcp_conn_tw_timer_set(conn); 814 833 break; 815 834 } … … 912 931 } 913 932 933 /** Time-Wait timeout handler. 934 * 935 * @param arg Connection 936 */ 937 static void tw_timeout_func(void *arg) 938 { 939 tcp_conn_t *conn = (tcp_conn_t *) arg; 940 941 log_msg(LVL_DEBUG, "tw_timeout_func(%p)", conn); 942 log_msg(LVL_DEBUG, " TW Timeout -> Closed"); 943 944 tcp_conn_remove(conn); 945 conn->cstate = st_closed; 946 } 947 948 /** Start or restart the Time-Wait timeout. 949 * 950 * @param conn Connection 951 */ 952 void tcp_conn_tw_timer_set(tcp_conn_t *conn) 953 { 954 fibril_timer_set(conn->tw_timer, TIME_WAIT_TIMEOUT, tw_timeout_func, 955 (void *)conn); 956 } 957 914 958 /** Trim segment to the receive window. 915 959 *
Note:
See TracChangeset
for help on using the changeset viewer.