Changeset 779541b in mainline
- Timestamp:
- 2015-05-09T13:43:50Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1d4b815
- Parents:
- 99ea91b2
- Location:
- uspace
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/inet/tcp.c
r99ea91b2 r779541b 30 30 * @{ 31 31 */ 32 /** @file UDP API32 /** @file TCP API 33 33 */ 34 34 … … 36 36 #include <inet/endpoint.h> 37 37 #include <inet/tcp.h> 38 #include <ipc/services.h> 39 #include <ipc/tcp.h> 40 #include <stdlib.h> 41 42 #include <stdio.h> 43 44 static void tcp_cb_conn(ipc_callid_t, ipc_call_t *, void *); 45 46 static int tcp_callback_create(tcp_t *tcp) 47 { 48 async_exch_t *exch = async_exchange_begin(tcp->sess); 49 50 printf("tcp_callback_create()\n"); 51 52 aid_t req = async_send_0(exch, TCP_CALLBACK_CREATE, NULL); 53 int rc = async_connect_to_me(exch, 0, 0, 0, tcp_cb_conn, tcp); 54 async_exchange_end(exch); 55 56 if (rc != EOK) 57 return rc; 58 59 sysarg_t retval; 60 async_wait_for(req, &retval); 61 62 return retval; 63 } 38 64 39 65 int tcp_create(tcp_t **rtcp) 40 66 { 41 return 0; 67 tcp_t *tcp; 68 service_id_t tcp_svcid; 69 int rc; 70 71 printf("tcp_create()\n"); 72 73 tcp = calloc(1, sizeof(tcp_t)); 74 if (tcp == NULL) { 75 rc = ENOMEM; 76 goto error; 77 } 78 79 list_initialize(&tcp->conn); 80 list_initialize(&tcp->listener); 81 82 rc = loc_service_get_id(SERVICE_NAME_TCP, &tcp_svcid, 83 IPC_FLAG_BLOCKING); 84 if (rc != EOK) { 85 rc = EIO; 86 goto error; 87 } 88 89 tcp->sess = loc_service_connect(EXCHANGE_SERIALIZE, tcp_svcid, 90 IPC_FLAG_BLOCKING); 91 if (tcp->sess == NULL) { 92 rc = EIO; 93 goto error; 94 } 95 96 rc = tcp_callback_create(tcp); 97 if (rc != EOK) { 98 rc = EIO; 99 goto error; 100 } 101 102 *rtcp = tcp; 103 return EOK; 104 error: 105 free(tcp); 106 return rc; 42 107 } 43 108 44 109 void tcp_destroy(tcp_t *tcp) 45 110 { 111 if (tcp == NULL) 112 return; 113 114 async_hangup(tcp->sess); 115 free(tcp); 46 116 } 47 117 … … 49 119 tcp_conn_t **rconn) 50 120 { 51 return 0; 121 async_exch_t *exch; 122 tcp_conn_t *conn; 123 ipc_call_t answer; 124 125 printf("tcp_conn_create()\n"); 126 127 conn = calloc(1, sizeof(tcp_conn_t)); 128 if (conn == NULL) 129 return ENOMEM; 130 131 conn->data_avail = false; 132 fibril_mutex_initialize(&conn->lock); 133 fibril_condvar_initialize(&conn->cv); 134 135 exch = async_exchange_begin(tcp->sess); 136 aid_t req = async_send_0(exch, TCP_CONN_CREATE, &answer); 137 sysarg_t rc = async_data_write_start(exch, (void *)epp, 138 sizeof(inet_ep2_t)); 139 async_exchange_end(exch); 140 141 if (rc != EOK) { 142 sysarg_t rc_orig; 143 async_wait_for(req, &rc_orig); 144 if (rc_orig != EOK) 145 rc = rc_orig; 146 goto error; 147 } 148 149 async_wait_for(req, &rc); 150 if (rc != EOK) 151 goto error; 152 153 conn->tcp = tcp; 154 conn->id = IPC_GET_ARG1(answer); 155 conn->cb = cb; 156 conn->cb_arg = arg; 157 158 list_append(&conn->ltcp, &tcp->conn); 159 *rconn = conn; 160 161 return EOK; 162 error: 163 free(conn); 164 return (int) rc; 52 165 } 53 166 54 167 void tcp_conn_destroy(tcp_conn_t *conn) 55 168 { 169 async_exch_t *exch; 170 171 printf("tcp_conn_destroy()\n"); 172 173 if (conn == NULL) 174 return; 175 176 list_remove(&conn->ltcp); 177 178 exch = async_exchange_begin(conn->tcp->sess); 179 sysarg_t rc = async_req_1_0(exch, TCP_CONN_DESTROY, conn->id); 180 async_exchange_end(exch); 181 182 free(conn); 183 (void) rc; 184 } 185 186 static int tcp_conn_get(tcp_t *tcp, sysarg_t id, tcp_conn_t **rconn) 187 { 188 list_foreach(tcp->conn, ltcp, tcp_conn_t, conn) { 189 if (conn->id == id) { 190 *rconn = conn; 191 return EOK; 192 } 193 } 194 195 return EINVAL; 56 196 } 57 197 58 198 void *tcp_conn_userptr(tcp_conn_t *conn) 59 199 { 60 return NULL;200 return conn->cb_arg; 61 201 } 62 202 … … 64 204 void *larg, tcp_cb_t *cb, void *arg, tcp_listener_t **rlst) 65 205 { 206 async_exch_t *exch; 207 tcp_listener_t *lst; 208 ipc_call_t answer; 209 210 printf("tcp_listener_create()\n"); 211 212 lst = calloc(1, sizeof(tcp_listener_t)); 213 if (lst == NULL) 214 return ENOMEM; 215 216 exch = async_exchange_begin(tcp->sess); 217 aid_t req = async_send_0(exch, TCP_LISTENER_CREATE, &answer); 218 sysarg_t rc = async_data_write_start(exch, (void *)ep, 219 sizeof(inet_ep_t)); 220 async_exchange_end(exch); 221 222 if (rc != EOK) { 223 sysarg_t rc_orig; 224 async_wait_for(req, &rc_orig); 225 if (rc_orig != EOK) 226 rc = rc_orig; 227 goto error; 228 } 229 230 async_wait_for(req, &rc); 231 if (rc != EOK) 232 goto error; 233 234 lst->tcp = tcp; 235 lst->id = IPC_GET_ARG1(answer); 236 lst->lcb = lcb; 237 lst->lcb_arg = larg; 238 lst->cb = cb; 239 lst->cb_arg = arg; 240 241 list_append(&lst->ltcp, &tcp->listener); 242 *rlst = lst; 243 244 return EOK; 245 error: 246 free(lst); 247 return (int) rc; 248 } 249 250 void tcp_listener_destroy(tcp_listener_t *lst) 251 { 252 async_exch_t *exch; 253 254 printf("tcp_listener_destroy()\n"); 255 256 if (lst == NULL) 257 return; 258 259 list_remove(&lst->ltcp); 260 261 exch = async_exchange_begin(lst->tcp->sess); 262 sysarg_t rc = async_req_1_0(exch, TCP_LISTENER_DESTROY, lst->id); 263 async_exchange_end(exch); 264 265 free(lst); 266 (void) rc; 267 } 268 269 void *tcp_listener_userptr(tcp_listener_t *lst) 270 { 271 return lst->lcb_arg; 272 } 273 274 int tcp_conn_wait_connected(tcp_conn_t *conn) 275 { 276 async_usleep(1000 * 1000); 66 277 return 0; 67 278 } 68 279 69 void tcp_listener_destroy(tcp_listener_t *lst)70 {71 }72 73 void *tcp_listener_userptr(tcp_listener_t *lst)74 {75 return NULL;76 }77 78 79 int tcp_conn_wait_connected(tcp_conn_t *conn)80 {81 return 0;82 }83 84 280 int tcp_conn_send(tcp_conn_t *conn, const void *data, size_t bytes) 85 281 { 86 return 0; 87 } 282 async_exch_t *exch; 283 sysarg_t rc; 284 285 printf("tcp_conn_send()\n"); 286 287 exch = async_exchange_begin(conn->tcp->sess); 288 aid_t req = async_send_1(exch, TCP_CONN_SEND, conn->id, NULL); 289 290 rc = async_data_write_start(exch, data, bytes); 291 if (rc != EOK) { 292 async_forget(req); 293 return rc; 294 } 295 296 async_exchange_end(exch); 297 298 if (rc != EOK) { 299 async_forget(req); 300 return rc; 301 } 302 303 async_wait_for(req, &rc); 304 return rc; 305 } 306 88 307 89 308 int tcp_conn_send_fin(tcp_conn_t *conn) 90 309 { 91 return 0; 310 async_exch_t *exch; 311 312 printf("tcp_conn_send_fin()\n"); 313 314 exch = async_exchange_begin(conn->tcp->sess); 315 sysarg_t rc = async_req_1_0(exch, TCP_CONN_SEND_FIN, conn->id); 316 async_exchange_end(exch); 317 318 return rc; 92 319 } 93 320 94 321 int tcp_conn_push(tcp_conn_t *conn) 95 322 { 96 return 0; 97 } 98 99 void tcp_conn_reset(tcp_conn_t *conn) 100 { 101 } 102 323 async_exch_t *exch; 324 325 printf("tcp_conn_push()\n"); 326 327 exch = async_exchange_begin(conn->tcp->sess); 328 sysarg_t rc = async_req_1_0(exch, TCP_CONN_PUSH, conn->id); 329 async_exchange_end(exch); 330 331 return rc; 332 } 333 334 int tcp_conn_reset(tcp_conn_t *conn) 335 { 336 async_exch_t *exch; 337 338 printf("tcp_conn_reset()\n"); 339 340 exch = async_exchange_begin(conn->tcp->sess); 341 sysarg_t rc = async_req_1_0(exch, TCP_CONN_RESET, conn->id); 342 async_exchange_end(exch); 343 344 return rc; 345 } 103 346 104 347 int tcp_conn_recv(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv) 105 348 { 106 return 0; 349 async_exch_t *exch; 350 ipc_call_t answer; 351 352 printf("tcp_conn_recv() bsize=%zu\n", bsize); 353 354 fibril_mutex_lock(&conn->lock); 355 if (!conn->data_avail) { 356 printf("returning EAGAIN\n"); 357 fibril_mutex_unlock(&conn->lock); 358 return EAGAIN; 359 } 360 361 exch = async_exchange_begin(conn->tcp->sess); 362 aid_t req = async_send_1(exch, TCP_CONN_RECV, conn->id, &answer); 363 int rc = async_data_read_start(exch, buf, bsize); 364 async_exchange_end(exch); 365 366 if (rc != EOK) { 367 printf("got rc = %d\n", rc); 368 async_forget(req); 369 fibril_mutex_unlock(&conn->lock); 370 return rc; 371 } 372 373 sysarg_t retval; 374 async_wait_for(req, &retval); 375 if (retval != EOK) { 376 printf("got rc = %d\n", rc); 377 fibril_mutex_unlock(&conn->lock); 378 return retval; 379 } 380 381 *nrecv = IPC_GET_ARG1(answer); 382 fibril_mutex_unlock(&conn->lock); 383 return EOK; 107 384 } 108 385 109 386 int tcp_conn_recv_wait(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv) 110 387 { 111 return 0; 388 async_exch_t *exch; 389 ipc_call_t answer; 390 391 printf("tcp_conn_recv_wait() bsize=%zu\n", bsize); 392 again: 393 fibril_mutex_lock(&conn->lock); 394 while (!conn->data_avail) { 395 printf("wait for data to be avail\n"); 396 fibril_condvar_wait(&conn->cv, &conn->lock); 397 } 398 399 printf("tcp_conn_recv_wait - get data\n"); 400 exch = async_exchange_begin(conn->tcp->sess); 401 aid_t req = async_send_1(exch, TCP_CONN_RECV_WAIT, conn->id, &answer); 402 int rc = async_data_read_start(exch, buf, bsize); 403 printf("tcp_conn_recv_wait - rc = %d\n", rc); 404 async_exchange_end(exch); 405 406 if (rc != EOK) { 407 printf("got rc=%d\n", rc); 408 async_forget(req); 409 if (rc == EAGAIN) { 410 conn->data_avail = false; 411 fibril_mutex_unlock(&conn->lock); 412 goto again; 413 } 414 fibril_mutex_unlock(&conn->lock); 415 return rc; 416 } 417 418 sysarg_t retval; 419 async_wait_for(req, &retval); 420 if (retval != EOK) { 421 printf("got retval != EOK\n"); 422 if (rc == EAGAIN) { 423 printf("rc == EAGAIN\n"); 424 conn->data_avail = false; 425 } 426 fibril_mutex_unlock(&conn->lock); 427 return retval; 428 } 429 430 *nrecv = IPC_GET_ARG1(answer); 431 fibril_mutex_unlock(&conn->lock); 432 printf("tcp_conn_recv_wait: nrecv=%zu\n", *nrecv); 433 printf("received: '"); 434 size_t i; 435 for (i = 0; i < *nrecv; i++) { 436 putchar((char)((char *)buf)[i]); 437 } 438 printf("'\n"); 439 return EOK; 440 } 441 442 static void tcp_ev_connected(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 443 { 444 printf("tcp_ev_connected()\n"); 445 async_answer_0(iid, ENOTSUP); 446 } 447 448 static void tcp_ev_conn_failed(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 449 { 450 printf("tcp_ev_conn_failed()\n"); 451 async_answer_0(iid, ENOTSUP); 452 } 453 454 static void tcp_ev_conn_reset(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 455 { 456 printf("tcp_ev_conn_reset()\n"); 457 async_answer_0(iid, ENOTSUP); 458 } 459 460 static void tcp_ev_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 461 { 462 tcp_conn_t *conn; 463 sysarg_t conn_id; 464 int rc; 465 466 printf("tcp_ev_data()\n"); 467 conn_id = IPC_GET_ARG1(*icall); 468 469 rc = tcp_conn_get(tcp, conn_id, &conn); 470 if (rc != EOK) { 471 printf("conn ID %zu not found\n", 472 conn_id); 473 async_answer_0(iid, ENOENT); 474 return; 475 } 476 477 conn->data_avail = true; 478 fibril_condvar_broadcast(&conn->cv); 479 480 async_answer_0(iid, EOK); 481 } 482 483 static void tcp_ev_urg_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 484 { 485 printf("tcp_ev_urg_data()\n"); 486 async_answer_0(iid, ENOTSUP); 487 } 488 489 static void tcp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 490 { 491 tcp_t *tcp = (tcp_t *)arg; 492 493 async_answer_0(iid, EOK); 494 495 printf("tcp_cb_conn()\n"); 496 497 while (true) { 498 ipc_call_t call; 499 ipc_callid_t callid = async_get_call(&call); 500 501 printf("tcp_cb_conn() - msg %d\n", 502 (int)IPC_GET_IMETHOD(call)); 503 if (!IPC_GET_IMETHOD(call)) { 504 /* TODO: Handle hangup */ 505 return; 506 } 507 508 switch (IPC_GET_IMETHOD(call)) { 509 case TCP_EV_CONNECTED: 510 tcp_ev_connected(tcp, callid, &call); 511 break; 512 case TCP_EV_CONN_FAILED: 513 tcp_ev_conn_failed(tcp, callid, &call); 514 break; 515 case TCP_EV_CONN_RESET: 516 tcp_ev_conn_reset(tcp, callid, &call); 517 break; 518 case TCP_EV_DATA: 519 tcp_ev_data(tcp, callid, &call); 520 break; 521 case TCP_EV_URG_DATA: 522 tcp_ev_urg_data(tcp, callid, &call); 523 break; 524 default: 525 async_answer_0(callid, ENOTSUP); 526 break; 527 } 528 } 112 529 } 113 530 -
uspace/lib/c/generic/inet/udp.c
r99ea91b2 r779541b 42 42 #include <stdlib.h> 43 43 44 #include <stdio.h>45 46 44 static void udp_cb_conn(ipc_callid_t, ipc_call_t *, void *); 47 45 … … 50 48 async_exch_t *exch = async_exchange_begin(udp->sess); 51 49 52 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_callback_create() \n");50 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_callback_create()"); 53 51 54 52 aid_t req = async_send_0(exch, UDP_CALLBACK_CREATE, NULL); … … 71 69 int rc; 72 70 73 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_create() \n");71 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_create()"); 74 72 75 73 udp = calloc(1, sizeof(udp_t)); … … 124 122 ipc_call_t answer; 125 123 126 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_create() \n");124 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_create()"); 127 125 128 126 assoc = calloc(1, sizeof(udp_assoc_t)); … … 166 164 async_exch_t *exch; 167 165 168 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_destroy() \n");166 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_destroy()"); 169 167 170 168 if (assoc == NULL) … … 186 184 async_exch_t *exch; 187 185 188 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send_msg() \n");186 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send_msg()"); 189 187 190 188 exch = async_exchange_begin(assoc->udp->sess); … … 277 275 ipc_call_t answer; 278 276 279 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_rmsg_info() \n");277 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_rmsg_info()"); 280 278 281 279 exch = async_exchange_begin(udp->sess); … … 305 303 async_exch_t *exch; 306 304 307 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_rmsg_discard() \n");305 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_rmsg_discard()"); 308 306 309 307 exch = async_exchange_begin(udp->sess); … … 332 330 int rc; 333 331 334 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_ev_data() \n");332 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_ev_data()"); 335 333 336 334 while (true) { 337 335 rc = udp_rmsg_info(udp, &rmsg); 338 336 if (rc != EOK) { 339 log_msg(LOG_DEFAULT, LVL_NOTE, "Error getting message info \n");337 log_msg(LOG_DEFAULT, LVL_NOTE, "Error getting message info"); 340 338 break; 341 339 } … … 343 341 rc = udp_assoc_get(udp, rmsg.assoc_id, &assoc); 344 342 if (rc != EOK) { 345 log_msg(LOG_DEFAULT, LVL_NOTE, "assoc ID %zu not found \n",343 log_msg(LOG_DEFAULT, LVL_NOTE, "assoc ID %zu not found", 346 344 rmsg.assoc_id); 347 345 continue; … … 353 351 rc = udp_rmsg_discard(udp); 354 352 if (rc != EOK) { 355 log_msg(LOG_DEFAULT, LVL_NOTE, "Error discarding message \n");353 log_msg(LOG_DEFAULT, LVL_NOTE, "Error discarding message"); 356 354 break; 357 355 } … … 367 365 async_answer_0(iid, EOK); 368 366 369 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_cb_conn() \n");367 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_cb_conn()"); 370 368 371 369 while (true) { … … 373 371 ipc_callid_t callid = async_get_call(&call); 374 372 375 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_cb_conn() - msg %d \n",373 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_cb_conn() - msg %d", 376 374 (int)IPC_GET_IMETHOD(call)); 377 375 if (!IPC_GET_IMETHOD(call)) { -
uspace/lib/c/include/inet/tcp.h
r99ea91b2 r779541b 36 36 #define LIBC_INET_TCP_H_ 37 37 38 #include <fibril_synch.h> 38 39 #include <inet/addr.h> 39 40 #include <inet/endpoint.h> 40 41 #include <inet/inet.h> 41 42 43 /** TCP connection */ 42 44 typedef struct { 45 fibril_mutex_t lock; 46 fibril_condvar_t cv; 47 struct tcp *tcp; 48 link_t ltcp; 49 sysarg_t id; 50 struct tcp_cb *cb; 51 void *cb_arg; 52 /** Some received data available in TCP server */ 53 bool data_avail; 43 54 } tcp_conn_t; 44 55 56 /** TCP connection listener */ 45 57 typedef struct { 58 struct tcp *tcp; 59 link_t ltcp; 60 sysarg_t id; 61 struct tcp_listen_cb *lcb; 62 void *lcb_arg; 63 struct tcp_cb *cb; 64 void *cb_arg; 46 65 } tcp_listener_t; 47 66 48 typedef struct { 67 /** TCP connection callbacks */ 68 typedef struct tcp_cb { 49 69 void (*connected)(tcp_conn_t *); 50 70 void (*conn_failed)(tcp_conn_t *); … … 54 74 } tcp_cb_t; 55 75 56 typedef struct { 76 /** TCP listener callbacks */ 77 typedef struct tcp_listen_cb { 57 78 void (*new_conn)(tcp_listener_t *, tcp_conn_t *); 58 79 } tcp_listen_cb_t; 59 80 60 typedef struct { 81 /** TCP service */ 82 typedef struct tcp { 83 /** TCP session */ 84 async_sess_t *sess; 85 /** List of connections */ 86 list_t conn; /* of tcp_conn_t */ 87 /** List of listeners */ 88 list_t listener; /* of tcp_listener_t */ 61 89 } tcp_t; 62 90 … … 76 104 extern int tcp_conn_send_fin(tcp_conn_t *); 77 105 extern int tcp_conn_push(tcp_conn_t *); 78 extern voidtcp_conn_reset(tcp_conn_t *);106 extern int tcp_conn_reset(tcp_conn_t *); 79 107 80 108 extern int tcp_conn_recv(tcp_conn_t *, void *, size_t, size_t *); -
uspace/lib/c/include/inet/udp.h
r99ea91b2 r779541b 41 41 #include <inet/inet.h> 42 42 43 /** UDP link state */ 43 44 typedef enum { 44 45 udp_ls_down, … … 46 47 } udp_link_state_t; 47 48 49 /** UDP received message */ 48 50 typedef struct { 49 51 struct udp *udp; … … 53 55 } udp_rmsg_t; 54 56 57 /** UDP received error */ 55 58 typedef struct { 56 59 } udp_rerr_t; 57 60 61 /** UDP association */ 58 62 typedef struct { 59 63 struct udp *udp; … … 64 68 } udp_assoc_t; 65 69 70 /** UDP callbacks */ 66 71 typedef struct udp_cb { 67 72 void (*recv_msg)(udp_assoc_t *, udp_rmsg_t *); … … 70 75 } udp_cb_t; 71 76 77 /** UDP service */ 72 78 typedef struct udp { 73 79 /** UDP session */ -
uspace/lib/c/include/ipc/tcp.h
r99ea91b2 r779541b 39 39 40 40 typedef enum { 41 TCP_CONN_CREATE = IPC_FIRST_USER_METHOD, 41 TCP_CALLBACK_CREATE = IPC_FIRST_USER_METHOD, 42 TCP_CONN_CREATE, 42 43 TCP_CONN_DESTROY, 43 44 TCP_LISTENER_CREATE, … … 47 48 TCP_CONN_PUSH, 48 49 TCP_CONN_RESET, 49 TCP_CONN_RECV 50 TCP_CONN_RECV, 51 TCP_CONN_RECV_WAIT 50 52 } tcp_request_t; 51 53 52 54 typedef enum { 53 TCP_ CONNECTED = IPC_FIRST_USER_METHOD54 TCP_ CONN_FAILED,55 TCP_ CONN_RESET,56 TCP_ DATA_AVAIL,57 TCP_ URG_DATA58 } tcp_ notif_t;55 TCP_EV_CONNECTED = IPC_FIRST_USER_METHOD, 56 TCP_EV_CONN_FAILED, 57 TCP_EV_CONN_RESET, 58 TCP_EV_DATA, 59 TCP_EV_URG_DATA 60 } tcp_event_t; 59 61 60 62 typedef enum { 61 TCP_ NEW_CONN = IPC_FIRST_USER_METHOD62 } tcp_listen_ cb_t;63 TCP_LEV_NEW_CONN = IPC_FIRST_USER_METHOD 64 } tcp_listen_event_t; 63 65 64 66 #endif -
uspace/lib/http/src/http.c
r99ea91b2 r779541b 52 52 int rc; 53 53 54 rc = tcp_conn_recv (http->conn, buf, buf_size, &nrecv);54 rc = tcp_conn_recv_wait(http->conn, buf, buf_size, &nrecv); 55 55 if (rc != EOK) 56 56 return rc; -
uspace/srv/net/tcp/Makefile
r99ea91b2 r779541b 37 37 rqueue.c \ 38 38 segment.c \ 39 service.c \ 39 40 seq_no.c \ 40 41 tcp.c \ -
uspace/srv/net/tcp/conn.c
r99ea91b2 r779541b 121 121 fibril_condvar_initialize(&conn->cstate_cv); 122 122 123 conn->c state_cb = NULL;123 conn->cb = NULL; 124 124 125 125 conn->cstate = st_listen; … … 275 275 276 276 /* Run user callback function */ 277 if (conn->c state_cb!= NULL) {277 if (conn->cb != NULL && conn->cb->cstate_change != NULL) { 278 278 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_state_set() - run user CB"); 279 conn->c state_cb(conn, conn->cstate_cb_arg);279 conn->cb->cstate_change(conn, conn->cb_arg); 280 280 } else { 281 281 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_state_set() - no user CB"); … … 1007 1007 /* Signal to the receive function that new data has arrived */ 1008 1008 fibril_condvar_broadcast(&conn->rcv_buf_cv); 1009 if (conn->cb != NULL && conn->cb->recv_data != NULL) 1010 conn->cb->recv_data(conn, conn->cb_arg); 1009 1011 1010 1012 log_msg(LOG_DEFAULT, LVL_DEBUG, "Received %zu bytes of data.", xfer_size); … … 1098 1100 conn->rcv_buf_fin = true; 1099 1101 fibril_condvar_broadcast(&conn->rcv_buf_cv); 1102 if (conn->cb != NULL && conn->cb->recv_data != NULL) 1103 conn->cb->recv_data(conn, conn->cb_arg); 1100 1104 1101 1105 tcp_segment_delete(seg); -
uspace/srv/net/tcp/tcp.c
r99ea91b2 r779541b 48 48 #include "pdu.h" 49 49 #include "rqueue.h" 50 #include "service.h" 50 51 #include "std.h" 51 52 #include "tcp.h" … … 192 193 } 193 194 194 // rc = tcp_sock_init();195 //if (rc != EOK) {196 // log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing socketservice.");197 //return ENOENT;198 //}195 rc = tcp_service_init(); 196 if (rc != EOK) { 197 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing service."); 198 return ENOENT; 199 } 199 200 200 201 return EOK; -
uspace/srv/net/tcp/tcp_type.h
r99ea91b2 r779541b 96 96 TCP_EINVPREC, 97 97 /* Security/compartment not allowed */ 98 TCP_EINVCOMP 98 TCP_EINVCOMP, 99 TCP_EAGAIN 99 100 } tcp_error_t; 100 101 … … 154 155 typedef void (*tcp_cstate_cb_t)(tcp_conn_t *, void *); 155 156 157 /** Connection callbacks */ 158 typedef struct { 159 void (*cstate_change)(tcp_conn_t *, void *); 160 void (*recv_data)(tcp_conn_t *, void *); 161 } tcp_cb_t; 162 156 163 /** Connection */ 157 164 struct tcp_conn { … … 159 166 link_t link; 160 167 161 /** Connection state change callbackfunction */162 tcp_c state_cb_t cstate_cb;168 /** Connection callbacks function */ 169 tcp_cb_t *cb; 163 170 /** Argument to @c cstate_cb */ 164 void *c state_cb_arg;171 void *cb_arg; 165 172 166 173 /** Connection identification (local and foreign socket) */ … … 318 325 } tcp_pdu_t; 319 326 320 typedef struct { 327 /** TCP client connection */ 328 typedef struct tcp_cconn { 329 /** Connection */ 330 tcp_conn_t *conn; 331 /** Connection ID for the client */ 332 sysarg_t id; 333 /** Client */ 334 struct tcp_client *client; 335 link_t lclient; 336 } tcp_cconn_t; 337 338 /** TCP client listener */ 339 typedef struct tcp_clst { 340 /** Connection */ 341 tcp_conn_t *conn; 342 /** Listener ID for the client */ 343 sysarg_t id; 344 /** Client */ 345 struct tcp_client *client; 346 /** Link to tcp_client_t.clst */ 347 link_t lclient; 348 } tcp_clst_t; 349 350 /** TCP client */ 351 typedef struct tcp_client { 352 /** Client callbac session */ 321 353 async_sess_t *sess; 322 // socket_cores_t sockets; 354 /** Client's connections */ 355 list_t cconn; /* of tcp_cconn_t */ 356 /** Client's listeners */ 357 list_t clst; 323 358 } tcp_client_t; 324 359 … … 358 393 } tcp_sock_lconn_t; 359 394 360 361 395 #endif 362 396 -
uspace/srv/net/tcp/tqueue.c
r99ea91b2 r779541b 285 285 { 286 286 log_msg(LOG_DEFAULT, LVL_DEBUG, 287 "tcp_transmit_segment( f:(%u),l:(%u), %p)",287 "tcp_transmit_segment(l:(%u),f:(%u), %p)", 288 288 sp->local.port, sp->foreign.port, seg); 289 289 -
uspace/srv/net/tcp/ucall.c
r99ea91b2 r779541b 188 188 /* Wait for data to become available */ 189 189 while (conn->rcv_buf_used == 0 && !conn->rcv_buf_fin && !conn->reset) { 190 tcp_conn_unlock(conn); 191 return TCP_EAGAIN; 190 192 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_receive() - wait for data"); 191 193 fibril_condvar_wait(&conn->rcv_buf_cv, &conn->lock); … … 294 296 } 295 297 296 void tcp_uc_set_c state_cb(tcp_conn_t *conn, tcp_cstate_cb_tcb, void *arg)297 { 298 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_set_c tate_cb(%p, %p, %p)",298 void tcp_uc_set_cb(tcp_conn_t *conn, tcp_cb_t *cb, void *arg) 299 { 300 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_set_cb(%p, %p, %p)", 299 301 conn, cb, arg); 300 302 301 conn->c state_cb = cb;302 conn->c state_cb_arg = arg;303 conn->cb = cb; 304 conn->cb_arg = arg; 303 305 } 304 306 -
uspace/srv/net/tcp/ucall.h
r99ea91b2 r779541b 50 50 extern void tcp_uc_status(tcp_conn_t *, tcp_conn_status_t *); 51 51 extern void tcp_uc_delete(tcp_conn_t *); 52 extern void tcp_uc_set_c state_cb(tcp_conn_t *, tcp_cstate_cb_t, void *);52 extern void tcp_uc_set_cb(tcp_conn_t *, tcp_cb_t *, void *); 53 53 54 54 /* -
uspace/srv/net/udp/service.c
r99ea91b2 r779541b 160 160 udp_sock_t remote; 161 161 int rc; 162 char *la, *ra; 162 163 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_create_impl"); 163 164 164 165 local.addr = epp->local.addr; … … 166 167 remote.addr = epp->remote.addr; 167 168 remote.port = epp->remote.port; 168 169 la = (char *)"xxx";170 ra = (char *)"yyy";171 172 (void) inet_addr_format(&epp->local.addr, &la);173 (void) inet_addr_format(&epp->remote.addr, &ra);174 175 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_create_impl la=%s ra=%s",176 la, ra);177 169 178 170 assoc = udp_assoc_new(&local, &remote, NULL, NULL);
Note:
See TracChangeset
for help on using the changeset viewer.