source: mainline/uspace/srv/net/udp/sock.c@ ccb5165

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ccb5165 was ccb5165, checked in by Jiri Svoboda <jiri@…>, 12 years ago

Do not hold recv_buffer_lock while calling udp_uc_receive().

  • Property mode set to 100644
File size: 18.5 KB
Line 
1/*
2 * Copyright (c) 2008 Lukas Mejdrech
3 * Copyright (c) 2012 Jiri Svoboda
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup udp
31 * @{
32 */
33
34/**
35 * @file Socket provider
36 */
37
38#include <async.h>
39#include <byteorder.h>
40#include <errno.h>
41#include <inet/inet.h>
42#include <io/log.h>
43#include <ipc/services.h>
44#include <ipc/socket.h>
45#include <net/socket.h>
46#include <ns.h>
47
48#include "sock.h"
49#include "std.h"
50#include "udp_type.h"
51#include "ucall.h"
52
53/** Free ports pool start. */
54#define UDP_FREE_PORTS_START 1025
55
56/** Free ports pool end. */
57#define UDP_FREE_PORTS_END 65535
58
59static int last_used_port = UDP_FREE_PORTS_START - 1;
60static socket_ports_t gsock;
61
62static void udp_sock_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg);
63static int udp_sock_recv_fibril(void *arg);
64
65int udp_sock_init(void)
66{
67 socket_ports_initialize(&gsock);
68
69 async_set_client_connection(udp_sock_connection);
70
71 int rc = service_register(SERVICE_UDP);
72 if (rc != EOK)
73 return EEXIST;
74
75 return EOK;
76}
77
78static void udp_free_sock_data(socket_core_t *sock_core)
79{
80 udp_sockdata_t *socket;
81
82 socket = (udp_sockdata_t *)sock_core->specific_data;
83 (void)socket;
84
85 /* XXX We need to force the receive fibril to quit */
86}
87
88static void udp_sock_notify_data(socket_core_t *sock_core)
89{
90 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_notify_data(%d)", sock_core->socket_id);
91 async_exch_t *exch = async_exchange_begin(sock_core->sess);
92 async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t) sock_core->socket_id,
93 UDP_FRAGMENT_SIZE, 0, 0, 1);
94 async_exchange_end(exch);
95}
96
97static void udp_sock_socket(udp_client_t *client, ipc_callid_t callid, ipc_call_t call)
98{
99 udp_sockdata_t *sock;
100 socket_core_t *sock_core;
101 int sock_id;
102 int rc;
103 ipc_call_t answer;
104
105 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_socket()");
106 sock = calloc(1, sizeof(udp_sockdata_t));
107 if (sock == NULL) {
108 async_answer_0(callid, ENOMEM);
109 return;
110 }
111
112 fibril_mutex_initialize(&sock->lock);
113 sock->client = client;
114
115 sock->recv_buffer_used = 0;
116 sock->recv_error = UDP_EOK;
117 fibril_mutex_initialize(&sock->recv_buffer_lock);
118 fibril_condvar_initialize(&sock->recv_buffer_cv);
119
120 rc = udp_uc_create(&sock->assoc);
121 if (rc != EOK) {
122 free(sock);
123 async_answer_0(callid, rc);
124 return;
125 }
126
127 sock->recv_fibril = fibril_create(udp_sock_recv_fibril, sock);
128 if (sock->recv_fibril == 0) {
129 udp_uc_destroy(sock->assoc);
130 free(sock);
131 async_answer_0(callid, ENOMEM);
132 return;
133 }
134
135 sock_id = SOCKET_GET_SOCKET_ID(call);
136 rc = socket_create(&client->sockets, client->sess, sock, &sock_id);
137 if (rc != EOK) {
138 fibril_destroy(sock->recv_fibril);
139 udp_uc_destroy(sock->assoc);
140 free(sock);
141 async_answer_0(callid, rc);
142 return;
143 }
144
145 fibril_add_ready(sock->recv_fibril);
146
147 sock_core = socket_cores_find(&client->sockets, sock_id);
148 assert(sock_core != NULL);
149 sock->sock_core = sock_core;
150
151 SOCKET_SET_SOCKET_ID(answer, sock_id);
152
153 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, UDP_FRAGMENT_SIZE);
154 SOCKET_SET_HEADER_SIZE(answer, sizeof(udp_header_t));
155 async_answer_3(callid, EOK, IPC_GET_ARG1(answer),
156 IPC_GET_ARG2(answer), IPC_GET_ARG3(answer));
157}
158
159static void udp_sock_bind(udp_client_t *client, ipc_callid_t callid, ipc_call_t call)
160{
161 int rc;
162 struct sockaddr_in *addr;
163 size_t addr_size;
164 socket_core_t *sock_core;
165 udp_sockdata_t *socket;
166 udp_sock_t fsock;
167 udp_error_t urc;
168
169 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_bind()");
170 log_msg(LOG_DEFAULT, LVL_DEBUG, " - async_data_write_accept");
171
172 addr = NULL;
173
174 rc = async_data_write_accept((void **) &addr, false, 0, 0, 0, &addr_size);
175 if (rc != EOK) {
176 async_answer_0(callid, rc);
177 goto out;
178 }
179
180 if (addr_size != sizeof(struct sockaddr_in)) {
181 async_answer_0(callid, EINVAL);
182 goto out;
183 }
184
185 log_msg(LOG_DEFAULT, LVL_DEBUG, " - call socket_bind");
186 rc = socket_bind(&client->sockets, &gsock, SOCKET_GET_SOCKET_ID(call),
187 addr, addr_size, UDP_FREE_PORTS_START, UDP_FREE_PORTS_END,
188 last_used_port);
189 if (rc != EOK) {
190 async_answer_0(callid, rc);
191 goto out;
192 }
193
194 log_msg(LOG_DEFAULT, LVL_DEBUG, " - call socket_cores_find");
195 sock_core = socket_cores_find(&client->sockets, SOCKET_GET_SOCKET_ID(call));
196 if (sock_core == NULL) {
197 async_answer_0(callid, ENOENT);
198 goto out;
199 }
200
201 socket = (udp_sockdata_t *)sock_core->specific_data;
202
203 fsock.addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr);
204 fsock.port = sock_core->port;
205 urc = udp_uc_set_local(socket->assoc, &fsock);
206
207 switch (urc) {
208 case UDP_EOK:
209 rc = EOK;
210 break;
211/* case TCP_ENOTEXIST:
212 rc = ENOTCONN;
213 break;
214 case TCP_ECLOSING:
215 rc = ENOTCONN;
216 break;
217 case TCP_ERESET:
218 rc = ECONNABORTED;
219 break;*/
220 default:
221 assert(false);
222 }
223
224 log_msg(LOG_DEFAULT, LVL_DEBUG, " - success");
225 async_answer_0(callid, rc);
226out:
227 if (addr != NULL)
228 free(addr);
229}
230
231static void udp_sock_listen(udp_client_t *client, ipc_callid_t callid, ipc_call_t call)
232{
233 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_listen()");
234 async_answer_0(callid, ENOTSUP);
235}
236
237static void udp_sock_connect(udp_client_t *client, ipc_callid_t callid, ipc_call_t call)
238{
239 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_connect()");
240 async_answer_0(callid, ENOTSUP);
241}
242
243static void udp_sock_accept(udp_client_t *client, ipc_callid_t callid, ipc_call_t call)
244{
245 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_accept()");
246 async_answer_0(callid, ENOTSUP);
247}
248
249static void udp_sock_sendto(udp_client_t *client, ipc_callid_t callid, ipc_call_t call)
250{
251 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_send()");
252
253 struct sockaddr_in *addr = NULL;
254 udp_sock_t fsock;
255 udp_sock_t *fsock_ptr;
256
257 if (IPC_GET_IMETHOD(call) == NET_SOCKET_SENDTO) {
258 size_t addr_size;
259 int rc = async_data_write_accept((void **) &addr, false,
260 0, 0, 0, &addr_size);
261 if (rc != EOK) {
262 async_answer_0(callid, rc);
263 goto out;
264 }
265
266 if (addr_size != sizeof(struct sockaddr_in)) {
267 async_answer_0(callid, EINVAL);
268 goto out;
269 }
270
271 fsock.addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr);
272 fsock.port = uint16_t_be2host(addr->sin_port);
273 fsock_ptr = &fsock;
274 } else
275 fsock_ptr = NULL;
276
277 int socket_id = SOCKET_GET_SOCKET_ID(call);
278
279 SOCKET_GET_FLAGS(call);
280
281 socket_core_t *sock_core =
282 socket_cores_find(&client->sockets, socket_id);
283 if (sock_core == NULL) {
284 async_answer_0(callid, ENOTSOCK);
285 goto out;
286 }
287
288 udp_sockdata_t *socket =
289 (udp_sockdata_t *) sock_core->specific_data;
290
291 if (sock_core->port <= 0) {
292 /* Implicitly bind socket to port */
293 int rc = socket_bind_free_port(&gsock, sock_core,
294 UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, last_used_port);
295 if (rc != EOK) {
296 async_answer_0(callid, rc);
297 goto out;
298 }
299
300 assert(sock_core->port > 0);
301
302 udp_error_t urc = udp_uc_set_local_port(socket->assoc,
303 sock_core->port);
304
305 if (urc != UDP_EOK) {
306 // TODO: better error handling
307 async_answer_0(callid, EINTR);
308 goto out;
309 }
310
311 last_used_port = sock_core->port;
312 }
313
314 fibril_mutex_lock(&socket->lock);
315
316 if (socket->assoc->ident.local.addr.ipv4 == UDP_IPV4_ANY) {
317 /* Determine local IP address */
318 inet_addr_t loc_addr, rem_addr;
319
320 rem_addr.ipv4 = fsock_ptr ? fsock.addr.ipv4 :
321 socket->assoc->ident.foreign.addr.ipv4;
322
323 int rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr);
324 if (rc != EOK) {
325 fibril_mutex_unlock(&socket->lock);
326 async_answer_0(callid, rc);
327 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_sendto: Failed to "
328 "determine local address.");
329 return;
330 }
331
332 socket->assoc->ident.local.addr.ipv4 = loc_addr.ipv4;
333 log_msg(LOG_DEFAULT, LVL_DEBUG, "Local IP address is %x",
334 socket->assoc->ident.local.addr.ipv4);
335 }
336
337 assert(socket->assoc != NULL);
338
339 int fragments = SOCKET_GET_DATA_FRAGMENTS(call);
340 for (int index = 0; index < fragments; index++) {
341 ipc_callid_t wcallid;
342 size_t length;
343
344 if (!async_data_write_receive(&wcallid, &length)) {
345 fibril_mutex_unlock(&socket->lock);
346 async_answer_0(callid, EINVAL);
347 goto out;
348 }
349
350 if (length > UDP_FRAGMENT_SIZE)
351 length = UDP_FRAGMENT_SIZE;
352
353 uint8_t buffer[UDP_FRAGMENT_SIZE];
354 int rc = async_data_write_finalize(wcallid, buffer, length);
355 if (rc != EOK) {
356 fibril_mutex_unlock(&socket->lock);
357 async_answer_0(callid, rc);
358 goto out;
359 }
360
361 udp_error_t urc =
362 udp_uc_send(socket->assoc, fsock_ptr, buffer, length, 0);
363
364 switch (urc) {
365 case UDP_EOK:
366 rc = EOK;
367 break;
368 case UDP_ENORES:
369 rc = ENOMEM;
370 break;
371 case UDP_EUNSPEC:
372 rc = EINVAL;
373 break;
374 case UDP_ENOROUTE:
375 rc = EIO;
376 break;
377 default:
378 assert(false);
379 }
380
381 if (rc != EOK) {
382 fibril_mutex_unlock(&socket->lock);
383 async_answer_0(callid, rc);
384 goto out;
385 }
386 }
387
388 ipc_call_t answer;
389
390 IPC_SET_ARG1(answer, 0);
391 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, UDP_FRAGMENT_SIZE);
392 async_answer_2(callid, EOK, IPC_GET_ARG1(answer),
393 IPC_GET_ARG2(answer));
394 fibril_mutex_unlock(&socket->lock);
395
396out:
397 if (addr != NULL)
398 free(addr);
399}
400
401static void udp_sock_recvfrom(udp_client_t *client, ipc_callid_t callid, ipc_call_t call)
402{
403 int socket_id;
404 int flags;
405 size_t addr_length, length;
406 socket_core_t *sock_core;
407 udp_sockdata_t *socket;
408 ipc_call_t answer;
409 ipc_callid_t rcallid;
410 size_t data_len;
411 udp_error_t urc;
412 udp_sock_t rsock;
413 struct sockaddr_in addr;
414 int rc;
415
416 log_msg(LOG_DEFAULT, LVL_DEBUG, "%p: udp_sock_recv[from]()", client);
417
418 socket_id = SOCKET_GET_SOCKET_ID(call);
419 flags = SOCKET_GET_FLAGS(call);
420
421 sock_core = socket_cores_find(&client->sockets, socket_id);
422 if (sock_core == NULL) {
423 async_answer_0(callid, ENOTSOCK);
424 return;
425 }
426
427 socket = (udp_sockdata_t *)sock_core->specific_data;
428 fibril_mutex_lock(&socket->lock);
429
430 if (socket->assoc == NULL) {
431 fibril_mutex_unlock(&socket->lock);
432 async_answer_0(callid, ENOTCONN);
433 return;
434 }
435
436 (void)flags;
437
438 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_recvfrom(): lock recv_buffer lock");
439 fibril_mutex_lock(&socket->recv_buffer_lock);
440 while (socket->recv_buffer_used == 0 && socket->recv_error == UDP_EOK) {
441 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_recvfrom(): wait for cv");
442 fibril_condvar_wait(&socket->recv_buffer_cv,
443 &socket->recv_buffer_lock);
444 }
445
446 log_msg(LOG_DEFAULT, LVL_DEBUG, "Got data in sock recv_buffer");
447
448 rsock = socket->recv_fsock;
449 data_len = socket->recv_buffer_used;
450 urc = socket->recv_error;
451
452 log_msg(LOG_DEFAULT, LVL_DEBUG, "**** recv data_len=%zu", data_len);
453
454 switch (urc) {
455 case UDP_EOK:
456 rc = EOK;
457 break;
458/* case TCP_ENOTEXIST:
459 case TCP_ECLOSING:
460 rc = ENOTCONN;
461 break;
462 case TCP_ERESET:
463 rc = ECONNABORTED;
464 break;*/
465 default:
466 assert(false);
467 }
468
469 log_msg(LOG_DEFAULT, LVL_DEBUG, "**** udp_uc_receive -> %d", rc);
470 if (rc != EOK) {
471 fibril_mutex_unlock(&socket->recv_buffer_lock);
472 fibril_mutex_unlock(&socket->lock);
473 async_answer_0(callid, rc);
474 return;
475 }
476
477 if (IPC_GET_IMETHOD(call) == NET_SOCKET_RECVFROM) {
478 /* Fill addr */
479 addr.sin_family = AF_INET;
480 addr.sin_addr.s_addr = host2uint32_t_be(rsock.addr.ipv4);
481 addr.sin_port = host2uint16_t_be(rsock.port);
482
483 log_msg(LOG_DEFAULT, LVL_DEBUG, "addr read receive");
484 if (!async_data_read_receive(&rcallid, &addr_length)) {
485 fibril_mutex_unlock(&socket->recv_buffer_lock);
486 fibril_mutex_unlock(&socket->lock);
487 async_answer_0(callid, EINVAL);
488 return;
489 }
490
491 if (addr_length > sizeof(addr))
492 addr_length = sizeof(addr);
493
494 log_msg(LOG_DEFAULT, LVL_DEBUG, "addr read finalize");
495 rc = async_data_read_finalize(rcallid, &addr, addr_length);
496 if (rc != EOK) {
497 fibril_mutex_unlock(&socket->recv_buffer_lock);
498 fibril_mutex_unlock(&socket->lock);
499 async_answer_0(callid, EINVAL);
500 return;
501 }
502 }
503
504 log_msg(LOG_DEFAULT, LVL_DEBUG, "data read receive");
505 if (!async_data_read_receive(&rcallid, &length)) {
506 fibril_mutex_unlock(&socket->recv_buffer_lock);
507 fibril_mutex_unlock(&socket->lock);
508 async_answer_0(callid, EINVAL);
509 return;
510 }
511
512 if (length > data_len)
513 length = data_len;
514
515 log_msg(LOG_DEFAULT, LVL_DEBUG, "data read finalize");
516 rc = async_data_read_finalize(rcallid, socket->recv_buffer, length);
517
518 if (length < data_len && rc == EOK)
519 rc = EOVERFLOW;
520
521 log_msg(LOG_DEFAULT, LVL_DEBUG, "read_data_length <- %zu", length);
522 IPC_SET_ARG2(answer, 0);
523 SOCKET_SET_READ_DATA_LENGTH(answer, length);
524 SOCKET_SET_ADDRESS_LENGTH(answer, sizeof(addr));
525 async_answer_3(callid, EOK, IPC_GET_ARG1(answer),
526 IPC_GET_ARG2(answer), IPC_GET_ARG3(answer));
527
528 socket->recv_buffer_used = 0;
529
530 fibril_condvar_broadcast(&socket->recv_buffer_cv);
531 fibril_mutex_unlock(&socket->recv_buffer_lock);
532 fibril_mutex_unlock(&socket->lock);
533}
534
535static void udp_sock_close(udp_client_t *client, ipc_callid_t callid, ipc_call_t call)
536{
537 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close()");
538 int socket_id = SOCKET_GET_SOCKET_ID(call);
539
540 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close() - find core");
541 socket_core_t *sock_core =
542 socket_cores_find(&client->sockets, socket_id);
543 if (sock_core == NULL) {
544 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close() - core not found");
545 async_answer_0(callid, ENOTSOCK);
546 return;
547 }
548
549 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close() - spec data");
550 udp_sockdata_t *socket =
551 (udp_sockdata_t *) sock_core->specific_data;
552 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close() - lock socket");
553 fibril_mutex_lock(&socket->lock);
554
555 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close() - lock socket buffer");
556 fibril_mutex_lock(&socket->recv_buffer_lock);
557 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_close - set socket->sock_core = NULL");
558 socket->sock_core = NULL;
559 fibril_mutex_unlock(&socket->recv_buffer_lock);
560
561 udp_uc_reset(socket->assoc);
562
563 int rc = socket_destroy(NULL, socket_id, &client->sockets, &gsock,
564 udp_free_sock_data);
565 if (rc != EOK) {
566 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_close - socket_destroy failed");
567 fibril_mutex_unlock(&socket->lock);
568 async_answer_0(callid, rc);
569 return;
570 }
571
572 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_close - broadcast recv_buffer_cv");
573 fibril_condvar_broadcast(&socket->recv_buffer_cv);
574
575 fibril_mutex_unlock(&socket->lock);
576 async_answer_0(callid, EOK);
577}
578
579static void udp_sock_getsockopt(udp_client_t *client, ipc_callid_t callid, ipc_call_t call)
580{
581 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_getsockopt()");
582 async_answer_0(callid, ENOTSUP);
583}
584
585static void udp_sock_setsockopt(udp_client_t *client, ipc_callid_t callid, ipc_call_t call)
586{
587 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_setsockopt()");
588 async_answer_0(callid, ENOTSUP);
589}
590
591static int udp_sock_recv_fibril(void *arg)
592{
593 udp_sockdata_t *sock = (udp_sockdata_t *)arg;
594 udp_error_t urc;
595 xflags_t xflags;
596 size_t rcvd;
597
598 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_recv_fibril()");
599
600 fibril_mutex_lock(&sock->recv_buffer_lock);
601
602 while (true) {
603 log_msg(LOG_DEFAULT, LVL_DEBUG, "[] wait for rcv buffer empty()");
604 while (sock->recv_buffer_used != 0 && sock->sock_core != NULL) {
605 fibril_condvar_wait(&sock->recv_buffer_cv,
606 &sock->recv_buffer_lock);
607 }
608
609 fibril_mutex_unlock(&sock->recv_buffer_lock);
610
611 log_msg(LOG_DEFAULT, LVL_DEBUG, "[] call udp_uc_receive()");
612 urc = udp_uc_receive(sock->assoc, sock->recv_buffer,
613 UDP_FRAGMENT_SIZE, &rcvd, &xflags, &sock->recv_fsock);
614 fibril_mutex_lock(&sock->recv_buffer_lock);
615 sock->recv_error = urc;
616
617 log_msg(LOG_DEFAULT, LVL_DEBUG, "[] udp_uc_receive -> %d", urc);
618
619 if (sock->sock_core != NULL)
620 udp_sock_notify_data(sock->sock_core);
621
622 if (urc != UDP_EOK) {
623 log_msg(LOG_DEFAULT, LVL_DEBUG, "[] urc != UDP_EOK, break");
624 fibril_condvar_broadcast(&sock->recv_buffer_cv);
625 break;
626 }
627
628 log_msg(LOG_DEFAULT, LVL_DEBUG, "[] got data - broadcast recv_buffer_cv");
629
630 sock->recv_buffer_used = rcvd;
631 fibril_condvar_broadcast(&sock->recv_buffer_cv);
632 }
633
634 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_recv_fibril() exited loop");
635 fibril_mutex_unlock(&sock->recv_buffer_lock);
636 udp_uc_destroy(sock->assoc);
637
638 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_recv_fibril() terminated");
639
640 return 0;
641}
642
643static void udp_sock_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
644{
645 ipc_callid_t callid;
646 ipc_call_t call;
647 udp_client_t client;
648
649 /* Accept the connection */
650 async_answer_0(iid, EOK);
651
652 client.sess = async_callback_receive(EXCHANGE_SERIALIZE);
653 socket_cores_initialize(&client.sockets);
654
655 while (true) {
656 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_connection: wait");
657 callid = async_get_call(&call);
658 if (!IPC_GET_IMETHOD(call))
659 break;
660
661 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_connection: METHOD=%d",
662 (int)IPC_GET_IMETHOD(call));
663
664 switch (IPC_GET_IMETHOD(call)) {
665 case NET_SOCKET:
666 udp_sock_socket(&client, callid, call);
667 break;
668 case NET_SOCKET_BIND:
669 udp_sock_bind(&client, callid, call);
670 break;
671 case NET_SOCKET_LISTEN:
672 udp_sock_listen(&client, callid, call);
673 break;
674 case NET_SOCKET_CONNECT:
675 udp_sock_connect(&client, callid, call);
676 break;
677 case NET_SOCKET_ACCEPT:
678 udp_sock_accept(&client, callid, call);
679 break;
680 case NET_SOCKET_SEND:
681 case NET_SOCKET_SENDTO:
682 udp_sock_sendto(&client, callid, call);
683 break;
684 case NET_SOCKET_RECV:
685 case NET_SOCKET_RECVFROM:
686 udp_sock_recvfrom(&client, callid, call);
687 break;
688 case NET_SOCKET_CLOSE:
689 udp_sock_close(&client, callid, call);
690 break;
691 case NET_SOCKET_GETSOCKOPT:
692 udp_sock_getsockopt(&client, callid, call);
693 break;
694 case NET_SOCKET_SETSOCKOPT:
695 udp_sock_setsockopt(&client, callid, call);
696 break;
697 default:
698 async_answer_0(callid, ENOTSUP);
699 break;
700 }
701 }
702
703 /* Clean up */
704 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_connection: Clean up");
705 async_hangup(client.sess);
706 socket_cores_release(NULL, &client.sockets, &gsock, udp_free_sock_data);
707}
708
709/**
710 * @}
711 */
Note: See TracBrowser for help on using the repository browser.