Changeset 8fb1bf82 in mainline for uspace/srv/net/tl/tcp/tcp.c
- Timestamp:
- 2010-11-25T13:42:50Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8df8415
- Parents:
- a93d79a (diff), eb667613 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/tcp.c
ra93d79a r8fb1bf82 28 28 29 29 /** @addtogroup tcp 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 35 * 34 * TCP module implementation. 35 * @see tcp.h 36 36 */ 37 38 #include "tcp.h" 39 #include "tcp_header.h" 40 #include "tcp_module.h" 37 41 38 42 #include <assert.h> … … 40 44 #include <fibril_synch.h> 41 45 #include <malloc.h> 42 / /TODO remove stdio46 /* TODO remove stdio */ 43 47 #include <stdio.h> 44 48 #include <errno.h> 45 #include <err.h>46 49 47 50 #include <ipc/ipc.h> … … 72 75 #include <tl_interface.h> 73 76 74 #include "tcp.h"75 #include "tcp_header.h"76 #include "tcp_module.h"77 78 77 /** TCP module name. */ 79 78 #define NAME "TCP protocol" … … 110 109 111 110 /** Returns a value indicating whether the value is in the interval respecting 112 * 111 * the possible overflow. 113 112 * 114 * The high end and/or the value may overflow, be lower than the low value. 115 * @param[in] lower The last value before the interval. 116 * @param[in] value The value to be checked. 117 * @param[in] higher_equal The last value in the interval. 113 * The high end and/or the value may overflow, be lower than the low value. 114 * 115 * @param[in] lower The last value before the interval. 116 * @param[in] value The value to be checked. 117 * @param[in] higher_equal The last value in the interval. 118 118 */ 119 119 #define IS_IN_INTERVAL_OVERFLOW(lower, value, higher_equal) \ … … 126 126 */ 127 127 typedef struct tcp_timeout tcp_timeout_t; 128 129 /** Type definition of the TCP timeout pointer.130 * @see tcp_timeout131 */132 typedef tcp_timeout_t *tcp_timeout_ref;133 128 134 129 /** TCP reply timeout data. … … 144 139 145 140 /** Local sockets. */ 146 socket_cores_ reflocal_sockets;141 socket_cores_t *local_sockets; 147 142 148 143 /** Socket identifier. */ … … 165 160 }; 166 161 167 /** Releases the packet and returns the result. 168 * @param[in] packet The packet queue to be released. 169 * @param[in] result The result to be returned. 170 * @return The result parameter. 171 */ 172 int tcp_release_and_return(packet_t packet, int result); 173 174 void tcp_prepare_operation_header(socket_core_ref socket, 175 tcp_socket_data_ref socket_data, tcp_header_ref header, int synchronize, 176 int finalize); 177 int tcp_prepare_timeout(int (*timeout_function)(void *tcp_timeout_t), 178 socket_core_ref socket, tcp_socket_data_ref socket_data, 179 size_t sequence_number, tcp_socket_state_t state, suseconds_t timeout, 180 int globals_read_only); 181 void tcp_free_socket_data(socket_core_ref socket); 182 183 int tcp_timeout(void *data); 184 185 int tcp_release_after_timeout(void *data); 186 187 int tcp_process_packet(device_id_t device_id, packet_t packet, 188 services_t error); 189 int tcp_connect_core(socket_core_ref socket, socket_cores_ref local_sockets, 190 struct sockaddr *addr, socklen_t addrlen); 191 int tcp_queue_prepare_packet(socket_core_ref socket, 192 tcp_socket_data_ref socket_data, packet_t packet, size_t data_length); 193 int tcp_queue_packet(socket_core_ref socket, tcp_socket_data_ref socket_data, 194 packet_t packet, size_t data_length); 195 packet_t tcp_get_packets_to_send(socket_core_ref socket, 196 tcp_socket_data_ref socket_data); 197 void tcp_send_packets(device_id_t device_id, packet_t packet); 198 199 void tcp_process_acknowledgement(socket_core_ref socket, 200 tcp_socket_data_ref socket_data, tcp_header_ref header); 201 packet_t tcp_send_prepare_packet(socket_core_ref socket, 202 tcp_socket_data_ref socket_data, packet_t packet, size_t data_length, 203 size_t sequence_number); 204 packet_t tcp_prepare_copy(socket_core_ref socket, 205 tcp_socket_data_ref socket_data, packet_t packet, size_t data_length, 206 size_t sequence_number); 207 void tcp_retransmit_packet(socket_core_ref socket, 208 tcp_socket_data_ref socket_data, size_t sequence_number); 209 int tcp_create_notification_packet(packet_t * packet, socket_core_ref socket, 210 tcp_socket_data_ref socket_data, int synchronize, int finalize); 211 void tcp_refresh_socket_data(tcp_socket_data_ref socket_data); 212 213 void tcp_initialize_socket_data(tcp_socket_data_ref socket_data); 214 215 int tcp_process_listen(socket_core_ref listening_socket, 216 tcp_socket_data_ref listening_socket_data, tcp_header_ref header, 217 packet_t packet, struct sockaddr *src, struct sockaddr *dest, 218 size_t addrlen); 219 int tcp_process_syn_sent(socket_core_ref socket, 220 tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet); 221 int tcp_process_syn_received(socket_core_ref socket, 222 tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet); 223 int tcp_process_established(socket_core_ref socket, 224 tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet, 225 int fragments, size_t total_length); 226 int tcp_queue_received_packet(socket_core_ref socket, 227 tcp_socket_data_ref socket_data, packet_t packet, int fragments, 228 size_t total_length); 229 230 int tcp_received_msg(device_id_t device_id, packet_t packet, 231 services_t receiver, services_t error); 232 int tcp_process_client_messages(ipc_callid_t callid, ipc_call_t call); 233 234 int tcp_listen_message(socket_cores_ref local_sockets, int socket_id, 235 int backlog); 236 int tcp_connect_message(socket_cores_ref local_sockets, int socket_id, 237 struct sockaddr *addr, socklen_t addrlen); 238 int tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, 239 int flags, size_t * addrlen); 240 int tcp_send_message(socket_cores_ref local_sockets, int socket_id, 241 int fragments, size_t * data_fragment_size, int flags); 242 int tcp_accept_message(socket_cores_ref local_sockets, int socket_id, 243 int new_socket_id, size_t * data_fragment_size, size_t * addrlen); 244 int tcp_close_message(socket_cores_ref local_sockets, int socket_id); 162 static int tcp_release_and_return(packet_t *, int); 163 static void tcp_prepare_operation_header(socket_core_t *, tcp_socket_data_t *, 164 tcp_header_t *, int synchronize, int); 165 static int tcp_prepare_timeout(int (*)(void *), socket_core_t *, 166 tcp_socket_data_t *, size_t, tcp_socket_state_t, suseconds_t, int); 167 static void tcp_free_socket_data(socket_core_t *); 168 169 static int tcp_timeout(void *); 170 171 static int tcp_release_after_timeout(void *); 172 173 static int tcp_process_packet(device_id_t, packet_t *, services_t); 174 static int tcp_connect_core(socket_core_t *, socket_cores_t *, 175 struct sockaddr *, socklen_t); 176 static int tcp_queue_prepare_packet(socket_core_t *, tcp_socket_data_t *, 177 packet_t *, size_t); 178 static int tcp_queue_packet(socket_core_t *, tcp_socket_data_t *, packet_t *, 179 size_t); 180 static packet_t *tcp_get_packets_to_send(socket_core_t *, tcp_socket_data_t *); 181 static void tcp_send_packets(device_id_t, packet_t *); 182 183 static void tcp_process_acknowledgement(socket_core_t *, tcp_socket_data_t *, 184 tcp_header_t *); 185 static packet_t *tcp_send_prepare_packet(socket_core_t *, tcp_socket_data_t *, 186 packet_t *, size_t, size_t); 187 static packet_t *tcp_prepare_copy(socket_core_t *, tcp_socket_data_t *, 188 packet_t *, size_t, size_t); 189 /* static */ void tcp_retransmit_packet(socket_core_t *, tcp_socket_data_t *, 190 size_t); 191 static int tcp_create_notification_packet(packet_t **, socket_core_t *, 192 tcp_socket_data_t *, int, int); 193 static void tcp_refresh_socket_data(tcp_socket_data_t *); 194 195 static void tcp_initialize_socket_data(tcp_socket_data_t *); 196 197 static int tcp_process_listen(socket_core_t *, tcp_socket_data_t *, 198 tcp_header_t *, packet_t *, struct sockaddr *, struct sockaddr *, size_t); 199 static int tcp_process_syn_sent(socket_core_t *, tcp_socket_data_t *, 200 tcp_header_t *, packet_t *); 201 static int tcp_process_syn_received(socket_core_t *, tcp_socket_data_t *, 202 tcp_header_t *, packet_t *); 203 static int tcp_process_established(socket_core_t *, tcp_socket_data_t *, 204 tcp_header_t *, packet_t *, int, size_t); 205 static int tcp_queue_received_packet(socket_core_t *, tcp_socket_data_t *, 206 packet_t *, int, size_t); 207 208 static int tcp_received_msg(device_id_t, packet_t *, services_t, services_t); 209 static int tcp_process_client_messages(ipc_callid_t, ipc_call_t); 210 211 static int tcp_listen_message(socket_cores_t *, int, int); 212 static int tcp_connect_message(socket_cores_t *, int, struct sockaddr *, 213 socklen_t); 214 static int tcp_recvfrom_message(socket_cores_t *, int, int, size_t *); 215 static int tcp_send_message(socket_cores_t *, int, int, size_t *, int); 216 static int tcp_accept_message(socket_cores_t *, int, int, size_t *, size_t *); 217 static int tcp_close_message(socket_cores_t *, int); 245 218 246 219 /** TCP global data. */ 247 220 tcp_globals_t tcp_globals; 248 221 222 /** Initializes the TCP module. 223 * 224 * @param[in] client_connection The client connection processing function. The 225 * module skeleton propagates its own one. 226 * @return EOK on success. 227 * @return ENOMEM if there is not enough memory left. 228 */ 249 229 int tcp_initialize(async_client_conn_t client_connection) 250 230 { 251 ERROR_DECLARE;231 int rc; 252 232 253 233 assert(client_connection); … … 260 240 tcp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_TCP, 261 241 SERVICE_TCP, client_connection); 262 if (tcp_globals.ip_phone < 0) 242 if (tcp_globals.ip_phone < 0) { 243 fibril_rwlock_write_unlock(&tcp_globals.lock); 263 244 return tcp_globals.ip_phone; 245 } 264 246 265 ERROR_PROPAGATE(socket_ports_initialize(&tcp_globals.sockets)); 266 if (ERROR_OCCURRED(packet_dimensions_initialize( 267 &tcp_globals.dimensions))) { 247 rc = socket_ports_initialize(&tcp_globals.sockets); 248 if (rc != EOK) 249 goto out; 250 251 rc = packet_dimensions_initialize(&tcp_globals.dimensions); 252 if (rc != EOK) { 268 253 socket_ports_destroy(&tcp_globals.sockets); 269 return ERROR_CODE;254 goto out; 270 255 } 271 256 272 257 tcp_globals.last_used_port = TCP_FREE_PORTS_START - 1; 258 259 out: 273 260 fibril_rwlock_write_unlock(&tcp_globals.lock); 274 275 return EOK; 276 } 277 278 int 279 tcp_received_msg(device_id_t device_id, packet_t packet, services_t receiver, 280 services_t error) 281 { 282 ERROR_DECLARE; 261 return rc; 262 } 263 264 int tcp_received_msg(device_id_t device_id, packet_t *packet, 265 services_t receiver, services_t error) 266 { 267 int rc; 283 268 284 269 if (receiver != SERVICE_TCP) … … 286 271 287 272 fibril_rwlock_write_lock(&tcp_globals.lock); 288 if (ERROR_OCCURRED(tcp_process_packet(device_id, packet, error))) 273 rc = tcp_process_packet(device_id, packet, error); 274 if (rc != EOK) 289 275 fibril_rwlock_write_unlock(&tcp_globals.lock); 290 276 291 printf("receive %d \n", ERROR_CODE); 292 293 return ERROR_CODE; 294 } 295 296 int tcp_process_packet(device_id_t device_id, packet_t packet, services_t error) 297 { 298 ERROR_DECLARE; 299 277 printf("receive %d \n", rc); 278 279 return rc; 280 } 281 282 int tcp_process_packet(device_id_t device_id, packet_t *packet, services_t error) 283 { 300 284 size_t length; 301 285 size_t offset; 302 286 int result; 303 tcp_header_ refheader;304 socket_core_ refsocket;305 tcp_socket_data_ refsocket_data;306 packet_t next_packet;287 tcp_header_t *header; 288 socket_core_t *socket; 289 tcp_socket_data_t *socket_data; 290 packet_t *next_packet; 307 291 size_t total_length; 308 292 uint32_t checksum; … … 313 297 struct sockaddr *dest; 314 298 size_t addrlen; 315 316 if (error) { 317 switch (error) { 318 case SERVICE_ICMP: 319 // process error 320 result = icmp_client_process_packet(packet, &type, 321 &code, NULL, NULL); 322 if (result < 0) 323 return tcp_release_and_return(packet, result); 324 325 length = (size_t) result; 326 if (ERROR_OCCURRED(packet_trim(packet, length, 0))) { 327 return tcp_release_and_return(packet, 328 ERROR_CODE); 329 } 330 break; 331 332 default: 333 return tcp_release_and_return(packet, ENOTSUP); 334 } 335 } 336 337 // TODO process received ipopts? 299 int rc; 300 301 switch (error) { 302 case SERVICE_NONE: 303 break; 304 case SERVICE_ICMP: 305 /* Process error */ 306 result = icmp_client_process_packet(packet, &type, &code, NULL, 307 NULL); 308 if (result < 0) 309 return tcp_release_and_return(packet, result); 310 311 length = (size_t) result; 312 rc = packet_trim(packet, length, 0); 313 if (rc != EOK) 314 return tcp_release_and_return(packet, rc); 315 break; 316 default: 317 return tcp_release_and_return(packet, ENOTSUP); 318 } 319 320 /* TODO process received ipopts? */ 338 321 result = ip_client_process_packet(packet, NULL, NULL, NULL, NULL, NULL); 339 322 if (result < 0) … … 349 332 return tcp_release_and_return(packet, NO_DATA); 350 333 351 // trim all but TCP header 352 if (ERROR_OCCURRED(packet_trim(packet, offset, 0))) 353 return tcp_release_and_return(packet, ERROR_CODE); 354 355 // get tcp header 356 header = (tcp_header_ref) packet_get_data(packet); 334 /* Trim all but TCP header */ 335 rc = packet_trim(packet, offset, 0); 336 if (rc != EOK) 337 return tcp_release_and_return(packet, rc); 338 339 /* Get tcp header */ 340 header = (tcp_header_t *) packet_get_data(packet); 357 341 if (!header) 358 342 return tcp_release_and_return(packet, NO_DATA); … … 367 351 addrlen = (size_t) result; 368 352 369 if (ERROR_OCCURRED(tl_set_address_port(src, addrlen,370 ntohs(header->source_port))))371 return tcp_release_and_return(packet, ERROR_CODE);353 rc = tl_set_address_port(src, addrlen, ntohs(header->source_port)); 354 if (rc != EOK) 355 return tcp_release_and_return(packet, rc); 372 356 373 / / find the destination socket357 /* Find the destination socket */ 374 358 socket = socket_port_find(&tcp_globals.sockets, 375 359 ntohs(header->destination_port), (const char *) src, addrlen); 376 360 if (!socket) { 377 / / find the listening destination socket361 /* Find the listening destination socket */ 378 362 socket = socket_port_find(&tcp_globals.sockets, 379 363 ntohs(header->destination_port), SOCKET_MAP_KEY_LISTENING, 380 364 0); 381 if (!socket) { 382 if (tl_prepare_icmp_packet(tcp_globals.net_phone, 383 tcp_globals.icmp_phone, packet, error) == EOK) { 384 icmp_destination_unreachable_msg( 385 tcp_globals.icmp_phone, ICMP_PORT_UNREACH, 386 0, packet); 387 } 388 return EADDRNOTAVAIL; 389 } 390 } 365 } 366 367 if (!socket) { 368 if (tl_prepare_icmp_packet(tcp_globals.net_phone, 369 tcp_globals.icmp_phone, packet, error) == EOK) { 370 icmp_destination_unreachable_msg(tcp_globals.icmp_phone, 371 ICMP_PORT_UNREACH, 0, packet); 372 } 373 return EADDRNOTAVAIL; 374 } 375 391 376 printf("socket id %d\n", socket->socket_id); 392 socket_data = (tcp_socket_data_ ref) socket->specific_data;377 socket_data = (tcp_socket_data_t *) socket->specific_data; 393 378 assert(socket_data); 394 379 395 / / some data received, clear the timeout counter380 /* Some data received, clear the timeout counter */ 396 381 socket_data->timeout_count = 0; 397 382 398 / / count the received packet fragments383 /* Count the received packet fragments */ 399 384 next_packet = packet; 400 385 fragments = 0; … … 402 387 total_length = 0; 403 388 do { 404 ++fragments;389 fragments++; 405 390 length = packet_get_data_length(next_packet); 406 391 if (length <= 0) … … 409 394 total_length += length; 410 395 411 / / add partial checksum if set396 /* Add partial checksum if set */ 412 397 if (!error) { 413 398 checksum = compute_checksum(checksum, … … 421 406 422 407 if (error) 423 goto error;408 goto has_error_service; 424 409 425 410 if (socket_data->state == TCP_SOCKET_LISTEN) { 426 427 411 if (socket_data->pseudo_header) { 428 412 free(socket_data->pseudo_header); … … 431 415 } 432 416 433 if (ERROR_OCCURRED(ip_client_get_pseudo_header(IPPROTO_TCP, src, 434 addrlen, dest, addrlen, total_length, 435 &socket_data->pseudo_header, &socket_data->headerlen))) { 417 rc = ip_client_get_pseudo_header(IPPROTO_TCP, src, addrlen, 418 dest, addrlen, total_length, &socket_data->pseudo_header, 419 &socket_data->headerlen); 420 if (rc != EOK) { 436 421 fibril_rwlock_write_unlock(socket_data->local_lock); 437 return tcp_release_and_return(packet, ERROR_CODE); 438 } 439 440 } else if (ERROR_OCCURRED(ip_client_set_pseudo_header_data_length( 441 socket_data->pseudo_header, socket_data->headerlen, 442 total_length))) { 443 fibril_rwlock_write_unlock(socket_data->local_lock); 444 return tcp_release_and_return(packet, ERROR_CODE); 422 return tcp_release_and_return(packet, rc); 423 } 424 } else { 425 rc = ip_client_set_pseudo_header_data_length( 426 socket_data->pseudo_header, socket_data->headerlen, 427 total_length); 428 if (rc != EOK) { 429 fibril_rwlock_write_unlock(socket_data->local_lock); 430 return tcp_release_and_return(packet, rc); 431 } 445 432 } 446 433 … … 452 439 fibril_rwlock_write_unlock(socket_data->local_lock); 453 440 454 if (ERROR_NONE(tl_prepare_icmp_packet(tcp_globals.net_phone, 455 tcp_globals.icmp_phone, packet, error))) { 456 // checksum error ICMP 441 rc = tl_prepare_icmp_packet(tcp_globals.net_phone, 442 tcp_globals.icmp_phone, packet, error); 443 if (rc == EOK) { 444 /* Checksum error ICMP */ 457 445 icmp_parameter_problem_msg(tcp_globals.icmp_phone, 458 446 ICMP_PARAM_POINTER, … … 464 452 } 465 453 466 error:454 has_error_service: 467 455 fibril_rwlock_read_unlock(&tcp_globals.lock); 468 456 469 / / TODO error reporting/handling457 /* TODO error reporting/handling */ 470 458 switch (socket_data->state) { 471 459 case TCP_SOCKET_LISTEN: 472 ERROR_CODE = tcp_process_listen(socket, socket_data, header,473 packet,src, dest, addrlen);460 rc = tcp_process_listen(socket, socket_data, header, packet, 461 src, dest, addrlen); 474 462 break; 475 463 case TCP_SOCKET_SYN_RECEIVED: 476 ERROR_CODE = tcp_process_syn_received(socket, socket_data,477 header,packet);464 rc = tcp_process_syn_received(socket, socket_data, header, 465 packet); 478 466 break; 479 467 case TCP_SOCKET_SYN_SENT: 480 ERROR_CODE = tcp_process_syn_sent(socket, socket_data, header, 481 packet); 468 rc = tcp_process_syn_sent(socket, socket_data, header, packet); 482 469 break; 483 470 case TCP_SOCKET_FIN_WAIT_1: 484 / / ack changing the state to FIN_WAIT_2 gets processed later471 /* ack changing the state to FIN_WAIT_2 gets processed later */ 485 472 case TCP_SOCKET_FIN_WAIT_2: 486 / / fin changing state to LAST_ACK gets processed later473 /* fin changing state to LAST_ACK gets processed later */ 487 474 case TCP_SOCKET_LAST_ACK: 488 / / ack releasing the socket get processed later475 /* ack releasing the socket get processed later */ 489 476 case TCP_SOCKET_CLOSING: 490 / / ack releasing the socket gets processed later477 /* ack releasing the socket gets processed later */ 491 478 case TCP_SOCKET_ESTABLISHED: 492 ERROR_CODE = tcp_process_established(socket, socket_data,493 header,packet, fragments, total_length);479 rc = tcp_process_established(socket, socket_data, header, 480 packet, fragments, total_length); 494 481 break; 495 482 default: … … 497 484 } 498 485 499 if (ERROR_CODE != EOK) { 500 printf("process %d\n", ERROR_CODE); 486 if (rc != EOK) { 501 487 fibril_rwlock_write_unlock(socket_data->local_lock); 488 printf("process %d\n", rc); 502 489 } 503 490 … … 505 492 } 506 493 507 int 508 tcp_process_established(socket_core_ref socket, tcp_socket_data_ref socket_data, 509 tcp_header_ref header, packet_t packet, int fragments, 494 int tcp_process_established(socket_core_t *socket, tcp_socket_data_t * 495 socket_data, tcp_header_t *header, packet_t *packet, int fragments, 510 496 size_t total_length) 511 497 { 512 ERROR_DECLARE; 513 514 packet_t next_packet; 515 packet_t tmp_packet; 498 packet_t *next_packet; 499 packet_t *tmp_packet; 516 500 uint32_t old_incoming; 517 501 size_t order; … … 520 504 size_t offset; 521 505 uint32_t new_sequence_number; 506 int rc; 522 507 523 508 assert(socket); … … 533 518 socket_data->fin_incoming = new_sequence_number; 534 519 535 / / trim begining if containing expected data520 /* Trim begining if containing expected data */ 536 521 if (IS_IN_INTERVAL_OVERFLOW(new_sequence_number, 537 522 socket_data->next_incoming, new_sequence_number + total_length)) { 538 523 539 / / get the acknowledged offset524 /* Get the acknowledged offset */ 540 525 if (socket_data->next_incoming < new_sequence_number) { 541 526 offset = new_sequence_number - … … 549 534 total_length -= offset; 550 535 length = packet_get_data_length(packet); 551 // trim the acknowledged data 536 537 /* Trim the acknowledged data */ 552 538 while (length <= offset) { 553 / / release the acknowledged packets539 /* Release the acknowledged packets */ 554 540 next_packet = pq_next(packet); 555 541 pq_release_remote(tcp_globals.net_phone, … … 560 546 } 561 547 562 if ((offset > 0) && (ERROR_OCCURRED(packet_trim(packet, 563 offset, 0)))) 564 return tcp_release_and_return(packet, ERROR_CODE); 548 if (offset > 0) { 549 rc = packet_trim(packet, offset, 0); 550 if (rc != EOK) 551 return tcp_release_and_return(packet, rc); 552 } 565 553 566 554 assert(new_sequence_number == socket_data->next_incoming); 567 555 } 568 556 569 / / release if overflowing the window557 /* Release if overflowing the window */ 570 558 /* 571 559 if (IS_IN_INTERVAL_OVERFLOW(socket_data->next_incoming + … … 594 582 if (length <= offset) 595 583 next_packet = pq_next(next_packet); 596 else if (ERROR_OCCURRED(packet_trim(next_packet, 0, 597 length - offset))) 598 return tcp_release_and_return(packet, 599 ERROR_CODE); 584 else { 585 rc = packet_trim(next_packet, 0, 586 length - offset)); 587 if (rc != EOK) 588 return tcp_release_and_return(packet, 589 rc); 590 } 600 591 offset -= length; 601 592 total_length -= length - offset; … … 614 605 } 615 606 */ 616 / / the expected one arrived?607 /* The expected one arrived? */ 617 608 if (new_sequence_number == socket_data->next_incoming) { 618 609 printf("expected\n"); 619 / / process acknowledgement610 /* Process acknowledgement */ 620 611 tcp_process_acknowledgement(socket, socket_data, header); 621 612 622 / / remove the header613 /* Remove the header */ 623 614 total_length -= TCP_HEADER_LENGTH(header); 624 if (ERROR_OCCURRED(packet_trim(packet,625 TCP_HEADER_LENGTH(header), 0)))626 return tcp_release_and_return(packet, ERROR_CODE);615 rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0); 616 if (rc != EOK) 617 return tcp_release_and_return(packet, rc); 627 618 628 619 if (total_length) { 629 ERROR_PROPAGATE(tcp_queue_received_packet(socket, 630 socket_data, packet, fragments, total_length)); 620 rc = tcp_queue_received_packet(socket, socket_data, 621 packet, fragments, total_length); 622 if (rc != EOK) 623 return rc; 631 624 } else { 632 625 total_length = 1; … … 636 629 packet = socket_data->incoming; 637 630 while (packet) { 638 639 if (ERROR_OCCURRED(pq_get_order(socket_data->incoming, 640 &order, NULL))) { 641 // remove the corrupted packet 631 rc = pq_get_order(socket_data->incoming, &order, NULL); 632 if (rc != EOK) { 633 /* Remove the corrupted packet */ 642 634 next_packet = pq_detach(packet); 643 635 if (packet == socket_data->incoming) … … 652 644 if (IS_IN_INTERVAL_OVERFLOW(sequence_number, 653 645 old_incoming, socket_data->next_incoming)) { 654 / / move to the next646 /* Move to the next */ 655 647 packet = pq_next(packet); 656 / / coninual data?648 /* Coninual data? */ 657 649 } else if (IS_IN_INTERVAL_OVERFLOW(old_incoming, 658 650 sequence_number, socket_data->next_incoming)) { 659 / / detach the packet651 /* Detach the packet */ 660 652 next_packet = pq_detach(packet); 661 653 if (packet == socket_data->incoming) 662 654 socket_data->incoming = next_packet; 663 / / get data length655 /* Get data length */ 664 656 length = packet_get_data_length(packet); 665 657 new_sequence_number = sequence_number + length; 666 658 if (length <= 0) { 667 / / remove the empty packet659 /* Remove the empty packet */ 668 660 pq_release_remote(tcp_globals.net_phone, 669 661 packet_get_id(packet)); … … 671 663 continue; 672 664 } 673 / / exactly following665 /* Exactly following */ 674 666 if (sequence_number == 675 667 socket_data->next_incoming) { 676 // queue received data 677 ERROR_PROPAGATE( 678 tcp_queue_received_packet(socket, 668 /* Queue received data */ 669 rc = tcp_queue_received_packet(socket, 679 670 socket_data, packet, 1, 680 packet_get_data_length(packet))); 671 packet_get_data_length(packet)); 672 if (rc != EOK) 673 return rc; 681 674 socket_data->next_incoming = 682 675 new_sequence_number; 683 676 packet = next_packet; 684 677 continue; 685 / / at least partly following data?686 } else if (IS_IN_INTERVAL_OVERFLOW(687 sequence_number, socket_data->next_incoming,688 new_sequence_number)) {678 /* At least partly following data? */ 679 } 680 if (IS_IN_INTERVAL_OVERFLOW(sequence_number, 681 socket_data->next_incoming, new_sequence_number)) { 689 682 if (socket_data->next_incoming < 690 683 new_sequence_number) { … … 696 689 new_sequence_number; 697 690 } 698 if (ERROR_NONE(packet_trim(packet, 699 length, 0))) { 700 // queue received data 701 ERROR_PROPAGATE( 702 tcp_queue_received_packet( 691 rc = packet_trim(packet,length, 0); 692 if (rc == EOK) { 693 /* Queue received data */ 694 rc = tcp_queue_received_packet( 703 695 socket, socket_data, packet, 704 696 1, packet_get_data_length( 705 packet))); 697 packet)); 698 if (rc != EOK) 699 return rc; 706 700 socket_data->next_incoming = 707 701 new_sequence_number; … … 710 704 } 711 705 } 712 / / remove the duplicit or corrupted packet706 /* Remove the duplicit or corrupted packet */ 713 707 pq_release_remote(tcp_globals.net_phone, 714 708 packet_get_id(packet)); … … 723 717 socket_data->next_incoming + socket_data->window)) { 724 718 printf("in window\n"); 725 / / process acknowledgement719 /* Process acknowledgement */ 726 720 tcp_process_acknowledgement(socket, socket_data, header); 727 721 728 / / remove the header722 /* Remove the header */ 729 723 total_length -= TCP_HEADER_LENGTH(header); 730 if (ERROR_OCCURRED(packet_trim(packet,731 TCP_HEADER_LENGTH(header), 0)))732 return tcp_release_and_return(packet, ERROR_CODE);724 rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0); 725 if (rc != EOK) 726 return tcp_release_and_return(packet, rc); 733 727 734 728 next_packet = pq_detach(packet); 735 729 length = packet_get_data_length(packet); 736 if (ERROR_OCCURRED(pq_add(&socket_data->incoming, packet, 737 new_sequence_number, length))) { 738 // remove the corrupted packets 730 rc = pq_add(&socket_data->incoming, packet, new_sequence_number, 731 length); 732 if (rc != EOK) { 733 /* Remove the corrupted packets */ 739 734 pq_release_remote(tcp_globals.net_phone, 740 735 packet_get_id(packet)); … … 746 741 tmp_packet = pq_detach(next_packet); 747 742 length = packet_get_data_length(next_packet); 748 if (ERROR_OCCURRED(pq_set_order(next_packet, 749 new_sequence_number, length)) || 750 ERROR_OCCURRED(pq_insert_after(packet, 751 next_packet))) { 743 744 rc = pq_set_order(next_packet, 745 new_sequence_number, length); 746 if (rc != EOK) { 747 pq_release_remote(tcp_globals.net_phone, 748 packet_get_id(next_packet)); 749 } 750 rc = pq_insert_after(packet, next_packet); 751 if (rc != EOK) { 752 752 pq_release_remote(tcp_globals.net_phone, 753 753 packet_get_id(next_packet)); … … 758 758 } else { 759 759 printf("unexpected\n"); 760 / / release duplicite or restricted760 /* Release duplicite or restricted */ 761 761 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 762 762 } 763 763 764 / / change state according to the acknowledging incoming fin764 /* Change state according to the acknowledging incoming fin */ 765 765 if (IS_IN_INTERVAL_OVERFLOW(old_incoming, socket_data->fin_incoming, 766 766 socket_data->next_incoming)) { … … 771 771 socket_data->state = TCP_SOCKET_CLOSING; 772 772 break; 773 //case TCP_ESTABLISHED:773 /*case TCP_ESTABLISHED:*/ 774 774 default: 775 775 socket_data->state = TCP_SOCKET_CLOSE_WAIT; … … 780 780 packet = tcp_get_packets_to_send(socket, socket_data); 781 781 if (!packet) { 782 // create the notification packet 783 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 784 socket_data, 0, 0)); 785 ERROR_PROPAGATE(tcp_queue_prepare_packet(socket, socket_data, 786 packet, 1)); 782 /* Create the notification packet */ 783 rc = tcp_create_notification_packet(&packet, socket, 784 socket_data, 0, 0); 785 if (rc != EOK) 786 return rc; 787 rc = tcp_queue_prepare_packet(socket, socket_data, packet, 1); 788 if (rc != EOK) 789 return rc; 787 790 packet = tcp_send_prepare_packet(socket, socket_data, packet, 1, 788 791 socket_data->last_outgoing + 1); … … 791 794 fibril_rwlock_write_unlock(socket_data->local_lock); 792 795 793 / / send the packet796 /* Send the packet */ 794 797 tcp_send_packets(socket_data->device_id, packet); 795 798 … … 797 800 } 798 801 799 int 800 tcp_queue_received_packet(socket_core_ref socket, 801 tcp_socket_data_ref socket_data, packet_t packet, int fragments, 802 int tcp_queue_received_packet(socket_core_t *socket, 803 tcp_socket_data_t *socket_data, packet_t *packet, int fragments, 802 804 size_t total_length) 803 805 { 804 ERROR_DECLARE; 805 806 packet_dimension_ref packet_dimension; 806 packet_dimension_t *packet_dimension; 807 int rc; 807 808 808 809 assert(socket); … … 813 814 assert(socket_data->window > total_length); 814 815 815 // queue the received packet 816 if (ERROR_OCCURRED(dyn_fifo_push(&socket->received, 817 packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE)) || 818 ERROR_OCCURRED(tl_get_ip_packet_dimension(tcp_globals.ip_phone, 819 &tcp_globals.dimensions, socket_data->device_id, 820 &packet_dimension))) { 821 return tcp_release_and_return(packet, ERROR_CODE); 822 } 823 824 // decrease the window size 816 /* Queue the received packet */ 817 rc = dyn_fifo_push(&socket->received, packet_get_id(packet), 818 SOCKET_MAX_RECEIVED_SIZE); 819 if (rc != EOK) 820 return tcp_release_and_return(packet, rc); 821 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 822 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 823 if (rc != EOK) 824 return tcp_release_and_return(packet, rc); 825 826 /* Decrease the window size */ 825 827 socket_data->window -= total_length; 826 828 827 / / notify the destination socket829 /* Notify the destination socket */ 828 830 async_msg_5(socket->phone, NET_SOCKET_RECEIVED, 829 831 (ipcarg_t) socket->socket_id, … … 835 837 } 836 838 837 int 838 tcp_process_syn_sent(socket_core_ref socket, tcp_socket_data_ref socket_data, 839 tcp_header_ref header, packet_t packet) 840 { 841 ERROR_DECLARE; 842 843 packet_t next_packet; 839 int tcp_process_syn_sent(socket_core_t *socket, tcp_socket_data_t * 840 socket_data, tcp_header_t *header, packet_t *packet) 841 { 842 packet_t *next_packet; 843 int rc; 844 844 845 845 assert(socket); … … 852 852 return tcp_release_and_return(packet, EINVAL); 853 853 854 / / process acknowledgement854 /* Process acknowledgement */ 855 855 tcp_process_acknowledgement(socket, socket_data, header); 856 856 857 857 socket_data->next_incoming = ntohl(header->sequence_number) + 1; 858 // release additional packets 858 859 /* Release additional packets */ 859 860 next_packet = pq_detach(packet); 860 861 if (next_packet) { … … 862 863 packet_get_id(next_packet)); 863 864 } 864 // trim if longer than the header 865 if ((packet_get_data_length(packet) > sizeof(*header)) && 866 ERROR_OCCURRED(packet_trim(packet, 0, 867 packet_get_data_length(packet) - sizeof(*header)))) { 868 return tcp_release_and_return(packet, ERROR_CODE); 869 } 865 866 /* Trim if longer than the header */ 867 if (packet_get_data_length(packet) > sizeof(*header)) { 868 rc = packet_trim(packet, 0, 869 packet_get_data_length(packet) - sizeof(*header)); 870 if (rc != EOK) 871 return tcp_release_and_return(packet, rc); 872 } 873 870 874 tcp_prepare_operation_header(socket, socket_data, header, 0, 0); 871 875 fibril_mutex_lock(&socket_data->operation.mutex); 872 876 socket_data->operation.result = tcp_queue_packet(socket, socket_data, 873 877 packet, 1); 878 874 879 if (socket_data->operation.result == EOK) { 875 880 socket_data->state = TCP_SOCKET_ESTABLISHED; … … 877 882 if (packet) { 878 883 fibril_rwlock_write_unlock( socket_data->local_lock); 879 / / send the packet884 /* Send the packet */ 880 885 tcp_send_packets(socket_data->device_id, packet); 881 / / signal the result886 /* Signal the result */ 882 887 fibril_condvar_signal( &socket_data->operation.condvar); 883 888 fibril_mutex_unlock( &socket_data->operation.mutex); … … 885 890 } 886 891 } 892 887 893 fibril_mutex_unlock(&socket_data->operation.mutex); 888 894 return tcp_release_and_return(packet, EINVAL); 889 895 } 890 896 891 int 892 tcp_process_listen(socket_core_ref listening_socket, 893 tcp_socket_data_ref listening_socket_data, tcp_header_ref header, 894 packet_t packet, struct sockaddr *src, struct sockaddr *dest, 897 int tcp_process_listen(socket_core_t *listening_socket, 898 tcp_socket_data_t *listening_socket_data, tcp_header_t *header, 899 packet_t *packet, struct sockaddr *src, struct sockaddr *dest, 895 900 size_t addrlen) 896 901 { 897 ERROR_DECLARE; 898 899 packet_t next_packet; 900 socket_core_ref socket; 901 tcp_socket_data_ref socket_data; 902 packet_t *next_packet; 903 socket_core_t *socket; 904 tcp_socket_data_t *socket_data; 902 905 int socket_id; 903 906 int listening_socket_id = listening_socket->socket_id; 904 907 int listening_port = listening_socket->port; 908 int rc; 905 909 906 910 assert(listening_socket); … … 913 917 return tcp_release_and_return(packet, EINVAL); 914 918 915 socket_data = (tcp_socket_data_ ref) malloc(sizeof(*socket_data));919 socket_data = (tcp_socket_data_t *) malloc(sizeof(*socket_data)); 916 920 if (!socket_data) 917 921 return tcp_release_and_return(packet, ENOMEM); … … 930 934 return tcp_release_and_return(packet, ENOMEM); 931 935 } 936 932 937 memcpy(socket_data->addr, src, socket_data->addrlen); 933 938 socket_data->dest_port = ntohs(header->source_port); 934 if (ERROR_OCCURRED(tl_set_address_port(socket_data->addr, 935 socket_data->addrlen, socket_data->dest_port))) { 939 rc = tl_set_address_port(socket_data->addr, socket_data->addrlen, 940 socket_data->dest_port); 941 if (rc != EOK) { 936 942 free(socket_data->addr); 937 943 free(socket_data); 938 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 939 return ERROR_CODE; 940 } 941 942 // create a socket 944 return tcp_release_and_return(packet, rc); 945 } 946 947 /* Create a socket */ 943 948 socket_id = -1; 944 if (ERROR_OCCURRED(socket_create(socket_data->local_sockets, 945 listening_socket->phone, socket_data, &socket_id))) { 949 rc = socket_create(socket_data->local_sockets, listening_socket->phone, 950 socket_data, &socket_id); 951 if (rc != EOK) { 946 952 free(socket_data->addr); 947 953 free(socket_data); 948 return tcp_release_and_return(packet, ERROR_CODE);954 return tcp_release_and_return(packet, rc); 949 955 } 950 956 … … 958 964 fibril_rwlock_write_lock(&tcp_globals.lock); 959 965 960 / / find the destination socket966 /* Find the destination socket */ 961 967 listening_socket = socket_port_find(&tcp_globals.sockets, 962 968 listening_port, SOCKET_MAP_KEY_LISTENING, 0); 963 if ( (!listening_socket)||969 if (!listening_socket || 964 970 (listening_socket->socket_id != listening_socket_id)) { 965 971 fibril_rwlock_write_unlock(&tcp_globals.lock); 966 / / a shadow may remain until app hangs up972 /* A shadow may remain until app hangs up */ 967 973 return tcp_release_and_return(packet, EOK /*ENOTSOCK*/); 968 974 } 969 975 listening_socket_data = 970 (tcp_socket_data_ ref) listening_socket->specific_data;976 (tcp_socket_data_t *) listening_socket->specific_data; 971 977 assert(listening_socket_data); 972 978 … … 976 982 socket_id); 977 983 if (!socket) { 978 / / where is the socket?!?984 /* Where is the socket?!? */ 979 985 fibril_rwlock_write_unlock(&tcp_globals.lock); 980 986 return ENOTSOCK; 981 987 } 982 socket_data = (tcp_socket_data_ ref) socket->specific_data;988 socket_data = (tcp_socket_data_t *) socket->specific_data; 983 989 assert(socket_data); 984 990 985 ERROR_CODE = socket_port_add(&tcp_globals.sockets, listening_port,986 socket,(const char *) socket_data->addr, socket_data->addrlen);991 rc = socket_port_add(&tcp_globals.sockets, listening_port, socket, 992 (const char *) socket_data->addr, socket_data->addrlen); 987 993 assert(socket == socket_port_find(&tcp_globals.sockets, listening_port, 988 994 (const char *) socket_data->addr, socket_data->addrlen)); 989 995 990 // ERROR_CODE= socket_bind_free_port(&tcp_globals.sockets, socket,996 // rc = socket_bind_free_port(&tcp_globals.sockets, socket, 991 997 // TCP_FREE_PORTS_START, TCP_FREE_PORTS_END, 992 998 // tcp_globals.last_used_port); 993 999 // tcp_globals.last_used_port = socket->port; 994 1000 fibril_rwlock_write_unlock(&tcp_globals.lock); 995 if ( ERROR_CODE!= EOK) {1001 if (rc != EOK) { 996 1002 socket_destroy(tcp_globals.net_phone, socket->socket_id, 997 1003 socket_data->local_sockets, &tcp_globals.sockets, 998 1004 tcp_free_socket_data); 999 return tcp_release_and_return(packet, ERROR_CODE);1005 return tcp_release_and_return(packet, rc); 1000 1006 } 1001 1007 … … 1003 1009 socket_data->next_incoming = ntohl(header->sequence_number) + 1; 1004 1010 1005 / / release additional packets1011 /* Release additional packets */ 1006 1012 next_packet = pq_detach(packet); 1007 1013 if (next_packet) { … … 1010 1016 } 1011 1017 1012 // trim if longer than the header 1013 if ((packet_get_data_length(packet) > sizeof(*header)) && 1014 ERROR_OCCURRED(packet_trim(packet, 0, 1015 packet_get_data_length(packet) - sizeof(*header)))) { 1018 /* Trim if longer than the header */ 1019 if (packet_get_data_length(packet) > sizeof(*header)) { 1020 rc = packet_trim(packet, 0, 1021 packet_get_data_length(packet) - sizeof(*header)); 1022 if (rc != EOK) { 1023 socket_destroy(tcp_globals.net_phone, socket->socket_id, 1024 socket_data->local_sockets, &tcp_globals.sockets, 1025 tcp_free_socket_data); 1026 return tcp_release_and_return(packet, rc); 1027 } 1028 } 1029 1030 tcp_prepare_operation_header(socket, socket_data, header, 1, 0); 1031 1032 rc = tcp_queue_packet(socket, socket_data, packet, 1); 1033 if (rc != EOK) { 1016 1034 socket_destroy(tcp_globals.net_phone, socket->socket_id, 1017 1035 socket_data->local_sockets, &tcp_globals.sockets, 1018 1036 tcp_free_socket_data); 1019 return tcp_release_and_return(packet, ERROR_CODE); 1020 } 1021 1022 tcp_prepare_operation_header(socket, socket_data, header, 1, 0); 1023 1024 if (ERROR_OCCURRED(tcp_queue_packet(socket, socket_data, packet, 1))) { 1025 socket_destroy(tcp_globals.net_phone, socket->socket_id, 1026 socket_data->local_sockets, &tcp_globals.sockets, 1027 tcp_free_socket_data); 1028 return ERROR_CODE; 1037 return rc; 1029 1038 } 1030 1039 … … 1040 1049 fibril_rwlock_write_unlock(socket_data->local_lock); 1041 1050 1042 / / send the packet1051 /* Send the packet */ 1043 1052 tcp_send_packets(socket_data->device_id, packet); 1044 1053 … … 1046 1055 } 1047 1056 1048 int 1049 tcp_process_syn_received(socket_core_ref socket, 1050 tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet) 1051 { 1052 ERROR_DECLARE; 1053 1054 socket_core_ref listening_socket; 1055 tcp_socket_data_ref listening_socket_data; 1057 int tcp_process_syn_received(socket_core_t *socket, 1058 tcp_socket_data_t *socket_data, tcp_header_t *header, packet_t *packet) 1059 { 1060 socket_core_t *listening_socket; 1061 tcp_socket_data_t *listening_socket_data; 1062 int rc; 1056 1063 1057 1064 assert(socket); … … 1064 1071 return tcp_release_and_return(packet, EINVAL); 1065 1072 1066 / / process acknowledgement1073 /* Process acknowledgement */ 1067 1074 tcp_process_acknowledgement(socket, socket_data, header); 1068 1075 … … 1074 1081 if (listening_socket) { 1075 1082 listening_socket_data = 1076 (tcp_socket_data_ ref) listening_socket->specific_data;1083 (tcp_socket_data_t *) listening_socket->specific_data; 1077 1084 assert(listening_socket_data); 1078 1085 1079 // queue the received packet 1080 if (ERROR_NONE(dyn_fifo_push(&listening_socket->accepted, 1081 (-1 * socket->socket_id), 1082 listening_socket_data->backlog))) { 1083 1084 // notify the destination socket 1086 /* Queue the received packet */ 1087 rc = dyn_fifo_push(&listening_socket->accepted, 1088 (-1 * socket->socket_id), listening_socket_data->backlog); 1089 if (rc == EOK) { 1090 /* Notify the destination socket */ 1085 1091 async_msg_5(socket->phone, NET_SOCKET_ACCEPTED, 1086 1092 (ipcarg_t) listening_socket->socket_id, … … 1092 1098 } 1093 1099 } 1094 / / send FIN1100 /* Send FIN */ 1095 1101 socket_data->state = TCP_SOCKET_FIN_WAIT_1; 1096 1102 1097 // create the notification packet 1098 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 1099 socket_data, 0, 1)); 1100 1101 // send the packet 1102 ERROR_PROPAGATE(tcp_queue_packet(socket, socket_data, packet, 1)); 1103 1104 // flush packets 1103 /* Create the notification packet */ 1104 rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1); 1105 if (rc != EOK) 1106 return rc; 1107 1108 /* Send the packet */ 1109 rc = tcp_queue_packet(socket, socket_data, packet, 1); 1110 if (rc != EOK) 1111 return rc; 1112 1113 /* Flush packets */ 1105 1114 packet = tcp_get_packets_to_send(socket, socket_data); 1106 1115 fibril_rwlock_write_unlock(socket_data->local_lock); 1107 1116 if (packet) { 1108 / / send the packet1117 /* Send the packet */ 1109 1118 tcp_send_packets(socket_data->device_id, packet); 1110 1119 } … … 1113 1122 } 1114 1123 1115 void 1116 tcp_process_acknowledgement(socket_core_ref socket, 1117 tcp_socket_data_ref socket_data, tcp_header_ref header) 1124 void tcp_process_acknowledgement(socket_core_t *socket, 1125 tcp_socket_data_t *socket_data, tcp_header_t *header) 1118 1126 { 1119 1127 size_t number; 1120 1128 size_t length; 1121 packet_t packet;1122 packet_t next;1123 packet_t acknowledged = NULL;1129 packet_t *packet; 1130 packet_t *next; 1131 packet_t *acknowledged = NULL; 1124 1132 uint32_t old; 1125 1133 … … 1133 1141 1134 1142 number = ntohl(header->acknowledgement_number); 1135 // if more data acknowledged 1143 1144 /* If more data acknowledged */ 1136 1145 if (number != socket_data->expected) { 1137 1146 old = socket_data->expected; … … 1144 1153 case TCP_SOCKET_LAST_ACK: 1145 1154 case TCP_SOCKET_CLOSING: 1146 // fin acknowledged - release the socket in 1147 // another fibril 1155 /* 1156 * FIN acknowledged - release the socket in 1157 * another fibril. 1158 */ 1148 1159 tcp_prepare_timeout(tcp_release_after_timeout, 1149 1160 socket, socket_data, 0, … … 1155 1166 } 1156 1167 } 1157 // update the treshold if higher than set 1168 1169 /* Update the treshold if higher than set */ 1158 1170 if (number + ntohs(header->window) > 1159 1171 socket_data->expected + socket_data->treshold) { … … 1161 1173 socket_data->expected; 1162 1174 } 1163 // set new expected sequence number 1175 1176 /* Set new expected sequence number */ 1164 1177 socket_data->expected = number; 1165 1178 socket_data->expected_count = 1; … … 1173 1186 socket_data->outgoing = next; 1174 1187 1175 / / add to acknowledged or release1188 /* Add to acknowledged or release */ 1176 1189 if (pq_add(&acknowledged, packet, 0, 0) != EOK) 1177 1190 pq_release_remote(tcp_globals.net_phone, … … 1181 1194 break; 1182 1195 } 1183 // release acknowledged 1196 1197 /* Release acknowledged */ 1184 1198 if (acknowledged) { 1185 1199 pq_release_remote(tcp_globals.net_phone, … … 1187 1201 } 1188 1202 return; 1189 // if the same as the previous time 1190 } 1203 /* If the same as the previous time */ 1204 } 1205 1191 1206 if (number == socket_data->expected) { 1192 / / increase the counter1193 ++socket_data->expected_count;1207 /* Increase the counter */ 1208 socket_data->expected_count++; 1194 1209 if (socket_data->expected_count == TCP_FAST_RETRANSMIT_COUNT) { 1195 1210 socket_data->expected_count = 1; 1196 / / TODO retransmit lock1211 /* TODO retransmit lock */ 1197 1212 //tcp_retransmit_packet(socket, socket_data, number); 1198 1213 } … … 1200 1215 } 1201 1216 1202 int tcp_message_standalone(ipc_callid_t callid, ipc_call_t * call, 1203 ipc_call_t * answer, int *answer_count) 1204 { 1205 ERROR_DECLARE; 1206 1207 packet_t packet; 1217 /** Processes the TCP message. 1218 * 1219 * @param[in] callid The message identifier. 1220 * @param[in] call The message parameters. 1221 * @param[out] answer The message answer parameters. 1222 * @param[out] answer_count The last parameter for the actual answer in the 1223 * answer parameter. 1224 * @return EOK on success. 1225 * @return ENOTSUP if the message is not known. 1226 * 1227 * @see tcp_interface.h 1228 * @see IS_NET_TCP_MESSAGE() 1229 */ 1230 int 1231 tcp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 1232 ipc_call_t *answer, int *answer_count) 1233 { 1234 packet_t *packet; 1235 int rc; 1208 1236 1209 1237 assert(call); … … 1214 1242 switch (IPC_GET_METHOD(*call)) { 1215 1243 case NET_TL_RECEIVED: 1216 //fibril_rwlock_read_lock(&tcp_globals.lock); 1217 if (ERROR_NONE(packet_translate_remote(tcp_globals.net_phone, 1218 &packet, IPC_GET_PACKET(call)))) { 1219 ERROR_CODE = tcp_received_msg(IPC_GET_DEVICE(call), 1220 packet, SERVICE_TCP, IPC_GET_ERROR(call)); 1221 } 1222 //fibril_rwlock_read_unlock(&tcp_globals.lock); 1223 return ERROR_CODE; 1224 1244 // fibril_rwlock_read_lock(&tcp_globals.lock); 1245 rc = packet_translate_remote(tcp_globals.net_phone, &packet, 1246 IPC_GET_PACKET(call)); 1247 if (rc != EOK) { 1248 // fibril_rwlock_read_unlock(&tcp_globals.lock); 1249 return rc; 1250 } 1251 rc = tcp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_TCP, 1252 IPC_GET_ERROR(call)); 1253 // fibril_rwlock_read_unlock(&tcp_globals.lock); 1254 return rc; 1225 1255 case IPC_M_CONNECT_TO_ME: 1226 1256 return tcp_process_client_messages(callid, *call); … … 1230 1260 } 1231 1261 1232 void tcp_refresh_socket_data(tcp_socket_data_ refsocket_data)1262 void tcp_refresh_socket_data(tcp_socket_data_t *socket_data) 1233 1263 { 1234 1264 assert(socket_data); … … 1246 1276 } 1247 1277 1248 void tcp_initialize_socket_data(tcp_socket_data_ refsocket_data)1278 void tcp_initialize_socket_data(tcp_socket_data_t *socket_data) 1249 1279 { 1250 1280 assert(socket_data); … … 1269 1299 ipc_call_t answer; 1270 1300 int answer_count; 1271 tcp_socket_data_ refsocket_data;1272 socket_core_ refsocket;1273 packet_dimension_ refpacket_dimension;1301 tcp_socket_data_t *socket_data; 1302 socket_core_t *socket; 1303 packet_dimension_t *packet_dimension; 1274 1304 1275 1305 /* … … 1285 1315 while (keep_on_going) { 1286 1316 1287 / / answer the call1317 /* Answer the call */ 1288 1318 answer_call(callid, res, &answer, answer_count); 1289 / / refresh data1319 /* Refresh data */ 1290 1320 refresh_answer(&answer, &answer_count); 1291 / / get the next call1321 /* Get the next call */ 1292 1322 callid = async_get_call(&call); 1293 1323 1294 / / process the call1324 /* Process the call */ 1295 1325 switch (IPC_GET_METHOD(call)) { 1296 1326 case IPC_M_PHONE_HUNGUP: … … 1301 1331 case NET_SOCKET: 1302 1332 socket_data = 1303 (tcp_socket_data_ ref) malloc(sizeof(*socket_data));1333 (tcp_socket_data_t *) malloc(sizeof(*socket_data)); 1304 1334 if (!socket_data) { 1305 1335 res = ENOMEM; … … 1348 1378 SOCKET_GET_SOCKET_ID(call)); 1349 1379 if (socket) { 1350 socket_data = (tcp_socket_data_ ref)1380 socket_data = (tcp_socket_data_t *) 1351 1381 socket->specific_data; 1352 1382 assert(socket_data); … … 1375 1405 if (res != EOK) 1376 1406 break; 1377 // the global lock may be released in the 1378 // tcp_connect_message() function 1407 /* 1408 * The global lock may be released in the 1409 * tcp_connect_message() function. 1410 */ 1379 1411 fibril_rwlock_write_lock(&tcp_globals.lock); 1380 1412 fibril_rwlock_write_lock(&lock); … … 1490 1522 } 1491 1523 1492 / / release the application phone1524 /* Release the application phone */ 1493 1525 ipc_hangup(app_phone); 1494 1526 1495 1527 printf("release\n"); 1496 / / release all local sockets1528 /* Release all local sockets */ 1497 1529 socket_cores_release(tcp_globals.net_phone, &local_sockets, 1498 1530 &tcp_globals.sockets, tcp_free_socket_data); … … 1503 1535 int tcp_timeout(void *data) 1504 1536 { 1505 tcp_timeout_ reftimeout = data;1537 tcp_timeout_t *timeout = data; 1506 1538 int keep_write_lock = false; 1507 socket_core_ refsocket;1508 tcp_socket_data_ refsocket_data;1539 socket_core_t *socket; 1540 tcp_socket_data_t *socket_data; 1509 1541 1510 1542 assert(timeout); 1511 1543 1512 / / sleep the given timeout1544 /* Sleep the given timeout */ 1513 1545 async_usleep(timeout->timeout); 1514 / / lock the globals1546 /* Lock the globals */ 1515 1547 if (timeout->globals_read_only) 1516 1548 fibril_rwlock_read_lock(&tcp_globals.lock); … … 1518 1550 fibril_rwlock_write_lock(&tcp_globals.lock); 1519 1551 1520 / / find the pending operation socket1552 /* Find the pending operation socket */ 1521 1553 socket = socket_port_find(&tcp_globals.sockets, timeout->port, 1522 1554 timeout->key, timeout->key_length); 1523 if (! (socket && (socket->socket_id == timeout->socket_id)))1555 if (!socket || (socket->socket_id != timeout->socket_id)) 1524 1556 goto out; 1525 1557 1526 socket_data = (tcp_socket_data_ ref) socket->specific_data;1558 socket_data = (tcp_socket_data_t *) socket->specific_data; 1527 1559 assert(socket_data); 1528 1560 if (socket_data->local_sockets != timeout->local_sockets) … … 1531 1563 fibril_rwlock_write_lock(socket_data->local_lock); 1532 1564 if (timeout->sequence_number) { 1533 / / increase the timeout counter;1534 ++socket_data->timeout_count;1565 /* Increase the timeout counter */ 1566 socket_data->timeout_count++; 1535 1567 if (socket_data->timeout_count == TCP_MAX_TIMEOUTS) { 1536 / / TODO release as connection lost1568 /* TODO release as connection lost */ 1537 1569 //tcp_refresh_socket_data(socket_data); 1538 1570 fibril_rwlock_write_unlock(socket_data->local_lock); 1539 1571 } else { 1540 / / retransmit1572 /* Retransmit */ 1541 1573 // tcp_retransmit_packet(socket, 1542 1574 // socket_data, timeout->sequence_number); … … 1545 1577 } else { 1546 1578 fibril_mutex_lock(&socket_data->operation.mutex); 1547 // set the timeout operation result if state not 1548 // changed 1579 /* Set the timeout operation result if state not changed */ 1549 1580 if (socket_data->state == timeout->state) { 1550 1581 socket_data->operation.result = ETIMEOUT; 1551 // notify the main fibril 1582 1583 /* Notify the main fibril */ 1552 1584 fibril_condvar_signal(&socket_data->operation.condvar); 1553 // keep the global write lock 1585 1586 /* Keep the global write lock */ 1554 1587 keep_write_lock = true; 1555 1588 } else { 1556 // operation is ok, do nothing 1557 // unlocking from now on, so the unlocki 1558 // order does not matter... 1589 /* 1590 * Operation is ok, do nothing. 1591 * Unlocking from now on, so the unlocking 1592 * order does not matter. 1593 */ 1559 1594 fibril_rwlock_write_unlock(socket_data->local_lock); 1560 1595 } … … 1563 1598 1564 1599 out: 1565 / / unlock only if no socket1600 /* Unlock only if no socket */ 1566 1601 if (timeout->globals_read_only) 1567 1602 fibril_rwlock_read_unlock(&tcp_globals.lock); 1568 1603 else if (!keep_write_lock) 1569 / / release if not desired1604 /* Release if not desired */ 1570 1605 fibril_rwlock_write_unlock(&tcp_globals.lock); 1571 1606 1572 / / release the timeout structure1607 /* Release the timeout structure */ 1573 1608 free(timeout); 1574 1609 return EOK; … … 1577 1612 int tcp_release_after_timeout(void *data) 1578 1613 { 1579 tcp_timeout_ reftimeout = data;1580 socket_core_ refsocket;1581 tcp_socket_data_ refsocket_data;1614 tcp_timeout_t *timeout = data; 1615 socket_core_t *socket; 1616 tcp_socket_data_t *socket_data; 1582 1617 fibril_rwlock_t *local_lock; 1583 1618 1584 1619 assert(timeout); 1585 1620 1586 / / sleep the given timeout1621 /* Sleep the given timeout */ 1587 1622 async_usleep(timeout->timeout); 1588 // lock the globals 1623 1624 /* Lock the globals */ 1589 1625 fibril_rwlock_write_lock(&tcp_globals.lock); 1590 // find the pending operation socket 1626 1627 /* Find the pending operation socket */ 1591 1628 socket = socket_port_find(&tcp_globals.sockets, timeout->port, 1592 1629 timeout->key, timeout->key_length); 1630 1593 1631 if (socket && (socket->socket_id == timeout->socket_id)) { 1594 socket_data = (tcp_socket_data_ ref) socket->specific_data;1632 socket_data = (tcp_socket_data_t *) socket->specific_data; 1595 1633 assert(socket_data); 1596 1634 if (socket_data->local_sockets == timeout->local_sockets) { … … 1603 1641 } 1604 1642 } 1605 // unlock the globals 1643 1644 /* Unlock the globals */ 1606 1645 fibril_rwlock_write_unlock(&tcp_globals.lock); 1607 // release the timeout structure 1646 1647 /* Release the timeout structure */ 1608 1648 free(timeout); 1649 1609 1650 return EOK; 1610 1651 } 1611 1652 1612 void 1613 tcp_retransmit_packet(socket_core_ref socket, tcp_socket_data_ref socket_data, 1614 size_t sequence_number) 1615 { 1616 packet_t packet; 1617 packet_t copy; 1653 void tcp_retransmit_packet(socket_core_t *socket, tcp_socket_data_t * 1654 socket_data, size_t sequence_number) 1655 { 1656 packet_t *packet; 1657 packet_t *copy; 1618 1658 size_t data_length; 1619 1659 … … 1622 1662 assert(socket->specific_data == socket_data); 1623 1663 1624 / / sent packet?1664 /* Sent packet? */ 1625 1665 packet = pq_find(socket_data->outgoing, sequence_number); 1626 1666 printf("retransmit %d\n", packet_get_id(packet)); … … 1638 1678 } 1639 1679 1640 int 1641 tcp_listen_message(socket_cores_ref local_sockets, int socket_id,int backlog)1642 { 1643 socket_core_ refsocket;1644 tcp_socket_data_ refsocket_data;1680 int tcp_listen_message(socket_cores_t *local_sockets, int socket_id, 1681 int backlog) 1682 { 1683 socket_core_t *socket; 1684 tcp_socket_data_t *socket_data; 1645 1685 1646 1686 assert(local_sockets); … … 1649 1689 return EINVAL; 1650 1690 1651 / / find the socket1691 /* Find the socket */ 1652 1692 socket = socket_cores_find(local_sockets, socket_id); 1653 1693 if (!socket) 1654 1694 return ENOTSOCK; 1655 1695 1656 / / get the socket specific data1657 socket_data = (tcp_socket_data_ ref) socket->specific_data;1696 /* Get the socket specific data */ 1697 socket_data = (tcp_socket_data_t *) socket->specific_data; 1658 1698 assert(socket_data); 1659 // set the backlog 1699 1700 /* Set the backlog */ 1660 1701 socket_data->backlog = backlog; 1661 1702 … … 1663 1704 } 1664 1705 1665 int 1666 tcp_connect_message(socket_cores_ref local_sockets, int socket_id, 1706 int tcp_connect_message(socket_cores_t *local_sockets, int socket_id, 1667 1707 struct sockaddr *addr, socklen_t addrlen) 1668 1708 { 1669 ERROR_DECLARE; 1670 1671 socket_core_ref socket; 1709 socket_core_t *socket; 1710 int rc; 1672 1711 1673 1712 assert(local_sockets); … … 1675 1714 assert(addrlen > 0); 1676 1715 1677 / / find the socket1716 /* Find the socket */ 1678 1717 socket = socket_cores_find(local_sockets, socket_id); 1679 1718 if (!socket) 1680 1719 return ENOTSOCK; 1681 1720 1682 if (ERROR_OCCURRED(tcp_connect_core(socket, local_sockets, addr,1683 addrlen))) {1721 rc = tcp_connect_core(socket, local_sockets, addr, addrlen); 1722 if (rc != EOK) { 1684 1723 tcp_free_socket_data(socket); 1685 / / unbind if bound1724 /* Unbind if bound */ 1686 1725 if (socket->port > 0) { 1687 1726 socket_ports_exclude(&tcp_globals.sockets, … … 1690 1729 } 1691 1730 } 1692 return ERROR_CODE; 1693 } 1694 1695 int 1696 tcp_connect_core(socket_core_ref socket, socket_cores_ref local_sockets, 1731 return rc; 1732 } 1733 1734 int tcp_connect_core(socket_core_t *socket, socket_cores_t *local_sockets, 1697 1735 struct sockaddr *addr, socklen_t addrlen) 1698 1736 { 1699 ERROR_DECLARE; 1700 1701 tcp_socket_data_ref socket_data; 1702 packet_t packet; 1737 tcp_socket_data_t *socket_data; 1738 packet_t *packet; 1739 int rc; 1703 1740 1704 1741 assert(socket); … … 1706 1743 assert(addrlen > 0); 1707 1744 1708 / / get the socket specific data1709 socket_data = (tcp_socket_data_ ref) socket->specific_data;1745 /* Get the socket specific data */ 1746 socket_data = (tcp_socket_data_t *) socket->specific_data; 1710 1747 assert(socket_data); 1711 1748 assert(socket->specific_data == socket_data); … … 1715 1752 return EINVAL; 1716 1753 1717 // get the destination port 1718 ERROR_PROPAGATE(tl_get_address_port(addr, addrlen, 1719 &socket_data->dest_port)); 1754 /* Get the destination port */ 1755 rc = tl_get_address_port(addr, addrlen, &socket_data->dest_port); 1756 if (rc != EOK) 1757 return rc; 1758 1720 1759 if (socket->port <= 0) { 1721 // try to find a free port 1722 ERROR_PROPAGATE(socket_bind_free_port(&tcp_globals.sockets, 1723 socket, TCP_FREE_PORTS_START, TCP_FREE_PORTS_END, 1724 tcp_globals.last_used_port)); 1725 // set the next port as the search starting port number 1760 /* Try to find a free port */ 1761 rc = socket_bind_free_port(&tcp_globals.sockets, socket, 1762 TCP_FREE_PORTS_START, TCP_FREE_PORTS_END, 1763 tcp_globals.last_used_port); 1764 if (rc != EOK) 1765 return rc; 1766 /* Set the next port as the search starting port number */ 1726 1767 tcp_globals.last_used_port = socket->port; 1727 1768 } 1728 1769 1729 ERROR_PROPAGATE(ip_get_route_req(tcp_globals.ip_phone, IPPROTO_TCP,1770 rc = ip_get_route_req(tcp_globals.ip_phone, IPPROTO_TCP, 1730 1771 addr, addrlen, &socket_data->device_id, 1731 &socket_data->pseudo_header, &socket_data->headerlen)); 1732 1733 // create the notification packet 1734 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 1735 socket_data, 1, 0)); 1736 1737 // unlock the globals and wait for an operation 1772 &socket_data->pseudo_header, &socket_data->headerlen); 1773 if (rc != EOK) 1774 return rc; 1775 1776 /* Create the notification packet */ 1777 rc = tcp_create_notification_packet(&packet, socket, socket_data, 1, 0); 1778 if (rc != EOK) 1779 return rc; 1780 1781 /* Unlock the globals and wait for an operation */ 1738 1782 fibril_rwlock_write_unlock(&tcp_globals.lock); 1739 1783 1740 1784 socket_data->addr = addr; 1741 1785 socket_data->addrlen = addrlen; 1742 // send the packet 1743 if (ERROR_OCCURRED(tcp_queue_packet(socket, socket_data, packet, 1)) || 1744 ERROR_OCCURRED(tcp_prepare_timeout(tcp_timeout, socket, socket_data, 1745 0, TCP_SOCKET_INITIAL, NET_DEFAULT_TCP_INITIAL_TIMEOUT, false))) { 1746 1786 1787 /* Send the packet */ 1788 1789 if (((rc = tcp_queue_packet(socket, socket_data, packet, 1)) != EOK) || 1790 ((rc = tcp_prepare_timeout(tcp_timeout, socket, socket_data, 0, 1791 TCP_SOCKET_INITIAL, NET_DEFAULT_TCP_INITIAL_TIMEOUT, false)) != 1792 EOK)) { 1747 1793 socket_data->addr = NULL; 1748 1794 socket_data->addrlen = 0; 1749 1795 fibril_rwlock_write_lock(&tcp_globals.lock); 1750 1751 1796 } else { 1752 1753 1797 packet = tcp_get_packets_to_send(socket, socket_data); 1754 1798 if (packet) { 1755 1799 fibril_mutex_lock(&socket_data->operation.mutex); 1756 1800 fibril_rwlock_write_unlock(socket_data->local_lock); 1757 // send the packet 1801 1802 /* Send the packet */ 1758 1803 printf("connecting %d\n", packet_get_id(packet)); 1759 1804 tcp_send_packets(socket_data->device_id, packet); 1760 1805 1761 / / wait for a reply1806 /* Wait for a reply */ 1762 1807 fibril_condvar_wait(&socket_data->operation.condvar, 1763 1808 &socket_data->operation.mutex); 1764 ERROR_CODE= socket_data->operation.result;1765 if ( ERROR_CODE!= EOK) {1809 rc = socket_data->operation.result; 1810 if (rc != EOK) { 1766 1811 socket_data->addr = NULL; 1767 1812 socket_data->addrlen = 0; … … 1770 1815 socket_data->addr = NULL; 1771 1816 socket_data->addrlen = 0; 1772 ERROR_CODE= EINTR;1817 rc = EINTR; 1773 1818 } 1774 1819 } 1775 1820 1776 1821 fibril_mutex_unlock(&socket_data->operation.mutex); 1777 1778 // return the result 1779 return ERROR_CODE; 1780 } 1781 1782 int 1783 tcp_queue_prepare_packet(socket_core_ref socket, 1784 tcp_socket_data_ref socket_data, packet_t packet, size_t data_length) 1785 { 1786 ERROR_DECLARE; 1787 1788 tcp_header_ref header; 1822 return rc; 1823 } 1824 1825 int tcp_queue_prepare_packet(socket_core_t *socket, 1826 tcp_socket_data_t *socket_data, packet_t *packet, size_t data_length) 1827 { 1828 tcp_header_t *header; 1829 int rc; 1789 1830 1790 1831 assert(socket); … … 1792 1833 assert(socket->specific_data == socket_data); 1793 1834 1794 / / get tcp header1795 header = (tcp_header_ ref) packet_get_data(packet);1835 /* Get TCP header */ 1836 header = (tcp_header_t *) packet_get_data(packet); 1796 1837 if (!header) 1797 1838 return NO_DATA; … … 1801 1842 header->sequence_number = htonl(socket_data->next_outgoing); 1802 1843 1803 if (ERROR_OCCURRED(packet_set_addr(packet, NULL, 1804 (uint8_t *) socket_data->addr, socket_data->addrlen))) 1844 rc = packet_set_addr(packet, NULL, (uint8_t *) socket_data->addr, 1845 socket_data->addrlen); 1846 if (rc != EOK) 1805 1847 return tcp_release_and_return(packet, EINVAL); 1806 1848 1807 / / remember the outgoing FIN1849 /* Remember the outgoing FIN */ 1808 1850 if (header->finalize) 1809 1851 socket_data->fin_outgoing = socket_data->next_outgoing; … … 1812 1854 } 1813 1855 1814 int 1815 tcp_queue_packet(socket_core_ref socket, tcp_socket_data_ref socket_data, 1816 packet_t packet, size_t data_length) 1817 { 1818 ERROR_DECLARE; 1856 int tcp_queue_packet(socket_core_t *socket, tcp_socket_data_t *socket_data, 1857 packet_t *packet, size_t data_length) 1858 { 1859 int rc; 1819 1860 1820 1861 assert(socket); … … 1822 1863 assert(socket->specific_data == socket_data); 1823 1864 1824 ERROR_PROPAGATE(tcp_queue_prepare_packet(socket, socket_data, packet, 1825 data_length)); 1826 1827 if (ERROR_OCCURRED(pq_add(&socket_data->outgoing, packet, 1828 socket_data->next_outgoing, data_length))) 1829 return tcp_release_and_return(packet, ERROR_CODE); 1865 rc = tcp_queue_prepare_packet(socket, socket_data, packet, data_length); 1866 if (rc != EOK) 1867 return rc; 1868 1869 rc = pq_add(&socket_data->outgoing, packet, socket_data->next_outgoing, 1870 data_length); 1871 if (rc != EOK) 1872 return tcp_release_and_return(packet, rc); 1830 1873 1831 1874 socket_data->next_outgoing += data_length; … … 1833 1876 } 1834 1877 1835 packet_t 1836 tcp_get_packets_to_send(socket_core_ref socket, tcp_socket_data_ref socket_data) 1837 { 1838 ERROR_DECLARE; 1839 1840 packet_t packet; 1841 packet_t copy; 1842 packet_t sending = NULL; 1843 packet_t previous = NULL; 1878 packet_t *tcp_get_packets_to_send(socket_core_t *socket, tcp_socket_data_t * 1879 socket_data) 1880 { 1881 packet_t *packet; 1882 packet_t *copy; 1883 packet_t *sending = NULL; 1884 packet_t *previous = NULL; 1844 1885 size_t data_length; 1886 int rc; 1845 1887 1846 1888 assert(socket); … … 1852 1894 pq_get_order(packet, NULL, &data_length); 1853 1895 1854 // send only if fits into the window 1855 // respecting the possible overflow 1896 /* 1897 * Send only if fits into the window, respecting the possible 1898 * overflow. 1899 */ 1856 1900 if (!IS_IN_INTERVAL_OVERFLOW( 1857 1901 (uint32_t) socket_data->last_outgoing, … … 1867 1911 if (!sending) { 1868 1912 sending = copy; 1869 } else if (ERROR_OCCURRED(pq_insert_after(previous, copy))) { 1870 pq_release_remote(tcp_globals.net_phone, 1871 packet_get_id(copy)); 1872 return sending; 1913 } else { 1914 rc = pq_insert_after(previous, copy); 1915 if (rc != EOK) { 1916 pq_release_remote(tcp_globals.net_phone, 1917 packet_get_id(copy)); 1918 return sending; 1919 } 1873 1920 } 1874 1921 1875 1922 previous = copy; 1876 1923 packet = pq_next(packet); 1877 // overflow occurred ? 1878 if ((!packet) && 1924 1925 /* Overflow occurred? */ 1926 if (!packet && 1879 1927 (socket_data->last_outgoing > socket_data->next_outgoing)) { 1880 1928 printf("gpts overflow\n"); 1881 / / continue from the beginning1929 /* Continue from the beginning */ 1882 1930 packet = socket_data->outgoing; 1883 1931 } … … 1888 1936 } 1889 1937 1890 packet_t 1891 tcp_send_prepare_packet(socket_core_ref socket, tcp_socket_data_ref socket_data, 1892 packet_t packet, size_t data_length, size_t sequence_number) 1893 { 1894 ERROR_DECLARE; 1895 1896 tcp_header_ref header; 1938 packet_t *tcp_send_prepare_packet(socket_core_t *socket, tcp_socket_data_t * 1939 socket_data, packet_t *packet, size_t data_length, size_t sequence_number) 1940 { 1941 tcp_header_t *header; 1897 1942 uint32_t checksum; 1943 int rc; 1898 1944 1899 1945 assert(socket); … … 1901 1947 assert(socket->specific_data == socket_data); 1902 1948 1903 / / adjust the pseudo header1904 if (ERROR_OCCURRED(ip_client_set_pseudo_header_data_length(1905 socket_data-> pseudo_header, socket_data->headerlen,1906 packet_get_data_length(packet)))) {1949 /* Adjust the pseudo header */ 1950 rc = ip_client_set_pseudo_header_data_length(socket_data->pseudo_header, 1951 socket_data->headerlen, packet_get_data_length(packet)); 1952 if (rc != EOK) { 1907 1953 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1908 1954 return NULL; 1909 1955 } 1910 1956 1911 / / get the header1912 header = (tcp_header_ ref) packet_get_data(packet);1957 /* Get the header */ 1958 header = (tcp_header_t *) packet_get_data(packet); 1913 1959 if (!header) { 1914 1960 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); … … 1917 1963 assert(ntohl(header->sequence_number) == sequence_number); 1918 1964 1919 / / adjust the header1965 /* Adjust the header */ 1920 1966 if (socket_data->next_incoming) { 1921 1967 header->acknowledgement_number = … … 1925 1971 header->window = htons(socket_data->window); 1926 1972 1927 / / checksum1973 /* Checksum */ 1928 1974 header->checksum = 0; 1929 1975 checksum = compute_checksum(0, socket_data->pseudo_header, 1930 1976 socket_data->headerlen); 1931 checksum = compute_checksum(checksum, (uint8_t *) packet_get_data(packet), 1977 checksum = compute_checksum(checksum, 1978 (uint8_t *) packet_get_data(packet), 1932 1979 packet_get_data_length(packet)); 1933 1980 header->checksum = htons(flip_checksum(compact_checksum(checksum))); 1934 1981 1935 // prepare the packet 1936 if (ERROR_OCCURRED(ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 1937 0, 0)) || ERROR_OCCURRED(tcp_prepare_timeout(tcp_timeout, socket, 1938 socket_data, sequence_number, socket_data->state, 1939 socket_data->timeout, true))) { 1982 /* Prepare the packet */ 1983 rc = ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 0, 0); 1984 if (rc != EOK) { 1940 1985 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1941 1986 return NULL; 1942 1987 } 1943 1988 1989 rc = tcp_prepare_timeout(tcp_timeout, socket, socket_data, 1990 sequence_number, socket_data->state, socket_data->timeout, true); 1991 if (rc != EOK) { 1992 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1993 return NULL; 1994 } 1995 1944 1996 return packet; 1945 1997 } 1946 1998 1947 packet_t 1948 tcp_prepare_copy(socket_core_ref socket, tcp_socket_data_ref socket_data, 1949 packet_t packet, size_t data_length, size_t sequence_number) 1950 { 1951 packet_t copy; 1999 packet_t *tcp_prepare_copy(socket_core_t *socket, tcp_socket_data_t * 2000 socket_data, packet_t *packet, size_t data_length, size_t sequence_number) 2001 { 2002 packet_t *copy; 1952 2003 1953 2004 assert(socket); … … 1955 2006 assert(socket->specific_data == socket_data); 1956 2007 1957 / / make a copy of the packet2008 /* Make a copy of the packet */ 1958 2009 copy = packet_get_copy(tcp_globals.net_phone, packet); 1959 2010 if (!copy) … … 1964 2015 } 1965 2016 1966 void tcp_send_packets(device_id_t device_id, packet_t packet)1967 { 1968 packet_t next;2017 void tcp_send_packets(device_id_t device_id, packet_t *packet) 2018 { 2019 packet_t *next; 1969 2020 1970 2021 while (packet) { … … 1976 2027 } 1977 2028 1978 void 1979 tcp_prepare_operation_header(socket_core_ref socket, 1980 tcp_socket_data_ref socket_data, tcp_header_ref header, int synchronize, 2029 void tcp_prepare_operation_header(socket_core_t *socket, 2030 tcp_socket_data_t *socket_data, tcp_header_t *header, int synchronize, 1981 2031 int finalize) 1982 2032 { … … 1994 2044 } 1995 2045 1996 int 1997 tcp_prepare_timeout(int (*timeout_function)(void *tcp_timeout_t), 1998 socket_core_ref socket, tcp_socket_data_ref socket_data, 2046 int tcp_prepare_timeout(int (*timeout_function)(void *tcp_timeout_t), 2047 socket_core_t *socket, tcp_socket_data_t *socket_data, 1999 2048 size_t sequence_number, tcp_socket_state_t state, suseconds_t timeout, 2000 2049 int globals_read_only) 2001 2050 { 2002 tcp_timeout_ refoperation_timeout;2051 tcp_timeout_t *operation_timeout; 2003 2052 fid_t fibril; 2004 2053 … … 2007 2056 assert(socket->specific_data == socket_data); 2008 2057 2009 / / prepare the timeout with key bundle structure2058 /* Prepare the timeout with key bundle structure */ 2010 2059 operation_timeout = malloc(sizeof(*operation_timeout) + 2011 2060 socket->key_length + 1); … … 2022 2071 operation_timeout->state = state; 2023 2072 2024 / / copy the key2073 /* Copy the key */ 2025 2074 operation_timeout->key = ((char *) operation_timeout) + 2026 2075 sizeof(*operation_timeout); … … 2029 2078 operation_timeout->key[operation_timeout->key_length] = '\0'; 2030 2079 2031 / / prepare the timeouting thread2080 /* Prepare the timeouting thread */ 2032 2081 fibril = fibril_create(timeout_function, operation_timeout); 2033 2082 if (!fibril) { 2034 2083 free(operation_timeout); 2035 return EPARTY; 2084 return EPARTY; /* FIXME: use another EC */ 2036 2085 } 2037 2086 // fibril_mutex_lock(&socket_data->operation.mutex); 2038 / / start the timeouting fibril2087 /* Start the timeout fibril */ 2039 2088 fibril_add_ready(fibril); 2040 2089 //socket_data->state = state; … … 2042 2091 } 2043 2092 2044 int 2045 tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags, 2046 size_t * addrlen) 2047 { 2048 ERROR_DECLARE; 2049 2050 socket_core_ref socket; 2051 tcp_socket_data_ref socket_data; 2093 int tcp_recvfrom_message(socket_cores_t *local_sockets, int socket_id, 2094 int flags, size_t *addrlen) 2095 { 2096 socket_core_t *socket; 2097 tcp_socket_data_t *socket_data; 2052 2098 int packet_id; 2053 packet_t packet;2099 packet_t *packet; 2054 2100 size_t length; 2101 int rc; 2055 2102 2056 2103 assert(local_sockets); 2057 2104 2058 / / find the socket2105 /* Find the socket */ 2059 2106 socket = socket_cores_find(local_sockets, socket_id); 2060 2107 if (!socket) 2061 2108 return ENOTSOCK; 2062 2109 2063 / / get the socket specific data2110 /* Get the socket specific data */ 2064 2111 if (!socket->specific_data) 2065 2112 return NO_DATA; 2066 2113 2067 socket_data = (tcp_socket_data_ ref) socket->specific_data;2068 2069 / / check state2114 socket_data = (tcp_socket_data_t *) socket->specific_data; 2115 2116 /* Check state */ 2070 2117 if ((socket_data->state != TCP_SOCKET_ESTABLISHED) && 2071 2118 (socket_data->state != TCP_SOCKET_CLOSE_WAIT)) 2072 2119 return ENOTCONN; 2073 2120 2074 / / send the source address if desired2121 /* Send the source address if desired */ 2075 2122 if (addrlen) { 2076 ERROR_PROPAGATE(data_reply(socket_data->addr, 2077 socket_data->addrlen)); 2123 rc = data_reply(socket_data->addr, socket_data->addrlen); 2124 if (rc != EOK) 2125 return rc; 2078 2126 *addrlen = socket_data->addrlen; 2079 2127 } 2080 2128 2081 / / get the next received packet2129 /* Get the next received packet */ 2082 2130 packet_id = dyn_fifo_value(&socket->received); 2083 2131 if (packet_id < 0) 2084 2132 return NO_DATA; 2085 2133 2086 ERROR_PROPAGATE(packet_translate_remote(tcp_globals.net_phone, &packet, 2087 packet_id)); 2088 2089 // reply the packets 2090 ERROR_PROPAGATE(socket_reply_packets(packet, &length)); 2091 2092 // release the packet 2134 rc = packet_translate_remote(tcp_globals.net_phone, &packet, packet_id); 2135 if (rc != EOK) 2136 return rc; 2137 2138 /* Reply the packets */ 2139 rc = socket_reply_packets(packet, &length); 2140 if (rc != EOK) 2141 return rc; 2142 2143 /* Release the packet */ 2093 2144 dyn_fifo_pop(&socket->received); 2094 2145 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 2095 // return the total length 2146 2147 /* Return the total length */ 2096 2148 return (int) length; 2097 2149 } 2098 2150 2099 int 2100 tcp_send_message(socket_cores_ref local_sockets, int socket_id, int fragments, 2101 size_t * data_fragment_size, int flags) 2102 { 2103 ERROR_DECLARE; 2104 2105 socket_core_ref socket; 2106 tcp_socket_data_ref socket_data; 2107 packet_dimension_ref packet_dimension; 2108 packet_t packet; 2151 int tcp_send_message(socket_cores_t *local_sockets, int socket_id, 2152 int fragments, size_t *data_fragment_size, int flags) 2153 { 2154 socket_core_t *socket; 2155 tcp_socket_data_t *socket_data; 2156 packet_dimension_t *packet_dimension; 2157 packet_t *packet; 2109 2158 size_t total_length; 2110 tcp_header_ refheader;2159 tcp_header_t *header; 2111 2160 int index; 2112 2161 int result; 2162 int rc; 2113 2163 2114 2164 assert(local_sockets); 2115 2165 assert(data_fragment_size); 2116 2166 2117 / / find the socket2167 /* Find the socket */ 2118 2168 socket = socket_cores_find(local_sockets, socket_id); 2119 2169 if (!socket) 2120 2170 return ENOTSOCK; 2121 2171 2122 / / get the socket specific data2172 /* Get the socket specific data */ 2123 2173 if (!socket->specific_data) 2124 2174 return NO_DATA; 2125 2175 2126 socket_data = (tcp_socket_data_ ref) socket->specific_data;2127 2128 / / check state2176 socket_data = (tcp_socket_data_t *) socket->specific_data; 2177 2178 /* Check state */ 2129 2179 if ((socket_data->state != TCP_SOCKET_ESTABLISHED) && 2130 2180 (socket_data->state != TCP_SOCKET_CLOSE_WAIT)) 2131 2181 return ENOTCONN; 2132 2182 2133 ERROR_PROPAGATE(tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2134 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension)); 2183 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2184 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 2185 if (rc != EOK) 2186 return rc; 2135 2187 2136 2188 *data_fragment_size = … … 2138 2190 packet_dimension->content : socket_data->data_fragment_size); 2139 2191 2140 for (index = 0; index < fragments; ++index) {2141 / / read the data fragment2192 for (index = 0; index < fragments; index++) { 2193 /* Read the data fragment */ 2142 2194 result = tl_socket_read_packet_data(tcp_globals.net_phone, 2143 2195 &packet, TCP_HEADER_SIZE, packet_dimension, … … 2147 2199 2148 2200 total_length = (size_t) result; 2149 // prefix the tcp header 2201 2202 /* Prefix the TCP header */ 2150 2203 header = PACKET_PREFIX(packet, tcp_header_t); 2151 2204 if (!header) … … 2153 2206 2154 2207 tcp_prepare_operation_header(socket, socket_data, header, 0, 0); 2155 ERROR_PROPAGATE(tcp_queue_packet(socket, socket_data, packet, 2156 0)); 2157 } 2158 2159 // flush packets 2208 rc = tcp_queue_packet(socket, socket_data, packet, 0); 2209 if (rc != EOK) 2210 return rc; 2211 } 2212 2213 /* Flush packets */ 2160 2214 packet = tcp_get_packets_to_send(socket, socket_data); 2161 2215 fibril_rwlock_write_unlock(socket_data->local_lock); … … 2163 2217 2164 2218 if (packet) { 2165 / / send the packet2219 /* Send the packet */ 2166 2220 tcp_send_packets(socket_data->device_id, packet); 2167 2221 } … … 2171 2225 2172 2226 int 2173 tcp_close_message(socket_cores_ref local_sockets, int socket_id) 2174 { 2175 ERROR_DECLARE; 2176 2177 socket_core_ref socket; 2178 tcp_socket_data_ref socket_data; 2179 packet_t packet; 2180 2181 // find the socket 2227 tcp_close_message(socket_cores_t *local_sockets, int socket_id) 2228 { 2229 socket_core_t *socket; 2230 tcp_socket_data_t *socket_data; 2231 packet_t *packet; 2232 int rc; 2233 2234 /* Find the socket */ 2182 2235 socket = socket_cores_find(local_sockets, socket_id); 2183 2236 if (!socket) 2184 2237 return ENOTSOCK; 2185 2238 2186 / / get the socket specific data2187 socket_data = (tcp_socket_data_ ref) socket->specific_data;2239 /* Get the socket specific data */ 2240 socket_data = (tcp_socket_data_t *) socket->specific_data; 2188 2241 assert(socket_data); 2189 2242 2190 / / check state2243 /* Check state */ 2191 2244 switch (socket_data->state) { 2192 2245 case TCP_SOCKET_ESTABLISHED: … … 2201 2254 2202 2255 default: 2203 / / just destroy2204 if (ERROR_NONE(socket_destroy(tcp_globals.net_phone, socket_id,2256 /* Just destroy */ 2257 rc = socket_destroy(tcp_globals.net_phone, socket_id, 2205 2258 local_sockets, &tcp_globals.sockets, 2206 tcp_free_socket_data))) { 2259 tcp_free_socket_data); 2260 if (rc == EOK) { 2207 2261 fibril_rwlock_write_unlock(socket_data->local_lock); 2208 2262 fibril_rwlock_write_unlock(&tcp_globals.lock); 2209 2263 } 2210 return ERROR_CODE; 2211 } 2212 2213 // send FIN 2214 // TODO should I wait to complete? 2215 2216 // create the notification packet 2217 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 2218 socket_data, 0, 1)); 2219 2220 // send the packet 2221 ERROR_PROPAGATE(tcp_queue_packet(socket, socket_data, packet, 1)); 2222 2223 // flush packets 2264 return rc; 2265 } 2266 2267 /* 2268 * Send FIN. 2269 * TODO should I wait to complete? 2270 */ 2271 2272 /* Create the notification packet */ 2273 rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1); 2274 if (rc != EOK) 2275 return rc; 2276 2277 /* Send the packet */ 2278 rc = tcp_queue_packet(socket, socket_data, packet, 1); 2279 if (rc != EOK) 2280 return rc; 2281 2282 /* Flush packets */ 2224 2283 packet = tcp_get_packets_to_send(socket, socket_data); 2225 2284 fibril_rwlock_write_unlock(socket_data->local_lock); … … 2227 2286 2228 2287 if (packet) { 2229 / / send the packet2288 /* Send the packet */ 2230 2289 tcp_send_packets(socket_data->device_id, packet); 2231 2290 } … … 2234 2293 } 2235 2294 2236 int 2237 tcp_create_notification_packet(packet_t * packet, socket_core_ref socket, 2238 tcp_socket_data_ref socket_data, int synchronize, int finalize) 2239 { 2240 ERROR_DECLARE; 2241 2242 packet_dimension_ref packet_dimension; 2243 tcp_header_ref header; 2295 int tcp_create_notification_packet(packet_t **packet, socket_core_t *socket, 2296 tcp_socket_data_t *socket_data, int synchronize, int finalize) 2297 { 2298 packet_dimension_t *packet_dimension; 2299 tcp_header_t *header; 2300 int rc; 2244 2301 2245 2302 assert(packet); 2246 2303 2247 // get the device packet dimension 2248 ERROR_PROPAGATE(tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2249 &tcp_globals.dimensions, socket_data->device_id, 2250 &packet_dimension)); 2251 2252 // get a new packet 2304 /* Get the device packet dimension */ 2305 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2306 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 2307 if (rc != EOK) 2308 return rc; 2309 2310 /* Get a new packet */ 2253 2311 *packet = packet_get_4_remote(tcp_globals.net_phone, TCP_HEADER_SIZE, 2254 2312 packet_dimension->addr_len, packet_dimension->prefix, … … 2258 2316 return ENOMEM; 2259 2317 2260 / / allocate space in the packet2318 /* Allocate space in the packet */ 2261 2319 header = PACKET_SUFFIX(*packet, tcp_header_t); 2262 2320 if (!header) … … 2269 2327 } 2270 2328 2271 int 2272 tcp_accept_message(socket_cores_ref local_sockets, int socket_id, 2273 int new_socket_id, size_t * data_fragment_size, size_t * addrlen) 2274 { 2275 ERROR_DECLARE; 2276 2277 socket_core_ref accepted; 2278 socket_core_ref socket; 2279 tcp_socket_data_ref socket_data; 2280 packet_dimension_ref packet_dimension; 2329 int tcp_accept_message(socket_cores_t *local_sockets, int socket_id, 2330 int new_socket_id, size_t *data_fragment_size, size_t *addrlen) 2331 { 2332 socket_core_t *accepted; 2333 socket_core_t *socket; 2334 tcp_socket_data_t *socket_data; 2335 packet_dimension_t *packet_dimension; 2336 int rc; 2281 2337 2282 2338 assert(local_sockets); … … 2284 2340 assert(addrlen); 2285 2341 2286 / / find the socket2342 /* Find the socket */ 2287 2343 socket = socket_cores_find(local_sockets, socket_id); 2288 2344 if (!socket) 2289 2345 return ENOTSOCK; 2290 2346 2291 / / get the socket specific data2292 socket_data = (tcp_socket_data_ ref) socket->specific_data;2347 /* Get the socket specific data */ 2348 socket_data = (tcp_socket_data_t *) socket->specific_data; 2293 2349 assert(socket_data); 2294 2350 2295 / / check state2351 /* Check state */ 2296 2352 if (socket_data->state != TCP_SOCKET_LISTEN) 2297 2353 return EINVAL; … … 2307 2363 return ENOTSOCK; 2308 2364 2309 / / get the socket specific data2310 socket_data = (tcp_socket_data_ ref) accepted->specific_data;2365 /* Get the socket specific data */ 2366 socket_data = (tcp_socket_data_t *) accepted->specific_data; 2311 2367 assert(socket_data); 2312 / / TODO can it be in another state?2368 /* TODO can it be in another state? */ 2313 2369 if (socket_data->state == TCP_SOCKET_ESTABLISHED) { 2314 ERROR_PROPAGATE(data_reply(socket_data->addr, 2315 socket_data->addrlen)); 2316 ERROR_PROPAGATE(tl_get_ip_packet_dimension( 2317 tcp_globals.ip_phone, &tcp_globals.dimensions, 2318 socket_data->device_id, &packet_dimension)); 2370 rc = data_reply(socket_data->addr, 2371 socket_data->addrlen); 2372 if (rc != EOK) 2373 return rc; 2374 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2375 &tcp_globals.dimensions, socket_data->device_id, 2376 &packet_dimension); 2377 if (rc != EOK) 2378 return rc; 2319 2379 *addrlen = socket_data->addrlen; 2320 2380 … … 2326 2386 2327 2387 if (new_socket_id > 0) { 2328 ERROR_PROPAGATE(socket_cores_update( 2329 local_sockets, accepted->socket_id, 2330 new_socket_id)); 2388 rc = socket_cores_update(local_sockets, 2389 accepted->socket_id, new_socket_id); 2390 if (rc != EOK) 2391 return rc; 2331 2392 accepted->socket_id = new_socket_id; 2332 2393 } … … 2339 2400 } 2340 2401 2341 void 2342 tcp_free_socket_data(socket_core_ref socket) 2343 { 2344 tcp_socket_data_ref socket_data; 2402 void tcp_free_socket_data(socket_core_t *socket) 2403 { 2404 tcp_socket_data_t *socket_data; 2345 2405 2346 2406 assert(socket); … … 2348 2408 printf("destroy_socket %d\n", socket->socket_id); 2349 2409 2350 / / get the socket specific data2351 socket_data = (tcp_socket_data_ ref) socket->specific_data;2410 /* Get the socket specific data */ 2411 socket_data = (tcp_socket_data_t *) socket->specific_data; 2352 2412 assert(socket_data); 2353 //free the pseudo header 2413 2414 /* Free the pseudo header */ 2354 2415 if (socket_data->pseudo_header) { 2355 2416 if (socket_data->headerlen) { … … 2360 2421 socket_data->pseudo_header = NULL; 2361 2422 } 2423 2362 2424 socket_data->headerlen = 0; 2363 // free the address 2425 2426 /* Free the address */ 2364 2427 if (socket_data->addr) { 2365 2428 if (socket_data->addrlen) { … … 2373 2436 } 2374 2437 2375 int tcp_release_and_return(packet_t packet, int result) 2438 /** Releases the packet and returns the result. 2439 * 2440 * @param[in] packet The packet queue to be released. 2441 * @param[in] result The result to be returned. 2442 * @return The result parameter. 2443 */ 2444 int tcp_release_and_return(packet_t *packet, int result) 2376 2445 { 2377 2446 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); … … 2381 2450 /** Default thread for new connections. 2382 2451 * 2383 * @param[in] iidThe initial message identifier.2384 * @param[in] icallThe initial message call structure.2452 * @param[in] iid The initial message identifier. 2453 * @param[in] icall The initial message call structure. 2385 2454 * 2386 2455 */ … … 2397 2466 int answer_count; 2398 2467 2399 /* 2400 Clear the answer structure 2401 */ 2468 /* Clear the answer structure */ 2402 2469 refresh_answer(&answer, &answer_count); 2403 2470 2404 /* 2405 Fetch the next message 2406 */ 2471 /* Fetch the next message */ 2407 2472 ipc_call_t call; 2408 2473 ipc_callid_t callid = async_get_call(&call); 2409 2474 2410 /* 2411 Process the message 2412 */ 2475 /* Process the message */ 2413 2476 int res = tl_module_message_standalone(callid, &call, &answer, 2414 2477 &answer_count); 2415 2478 2416 2479 /* 2417 End if said to either by the message or the processing result 2480 * End if told to either by the message or the processing 2481 * result. 2418 2482 */ 2419 2483 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || … … 2422 2486 2423 2487 /* 2424 2488 * Answer the message 2425 2489 */ 2426 2490 answer_call(callid, res, &answer, answer_count); … … 2430 2494 /** Starts the module. 2431 2495 * 2432 * @param argc The count of the command line arguments. Ignored parameter. 2433 * @param argv The command line parameters. Ignored parameter. 2434 * 2435 * @returns EOK on success. 2436 * @returns Other error codes as defined for each specific module start function. 2437 * 2496 * @return EOK on success. 2497 * @return Other error codes as defined for each specific module 2498 * start function. 2438 2499 */ 2439 2500 int 2440 2501 main(int argc, char *argv[]) 2441 2502 { 2442 ERROR_DECLARE; 2443 2444 /* 2445 Start the module 2446 */ 2447 if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection))) 2448 return ERROR_CODE; 2449 2450 return EOK; 2503 int rc; 2504 2505 rc = tl_module_start_standalone(tl_client_connection); 2506 return rc; 2451 2507 } 2452 2508
Note:
See TracChangeset
for help on using the changeset viewer.