~jsvoboda/helenos/dnsr

« back to all changes in this revision

Viewing changes to uspace/srv/net/udp/sock.c

  • Committer: Jiri Svoboda
  • Date: 2012-08-13 10:40:17 UTC
  • Revision ID: jiri@wiwaxia-20120813104017-t9y6pdrjuky39557
Terminate UDP receive fibril when socket is closed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
530
530
        udp_sockdata_t *socket;
531
531
        int rc;
532
532
 
533
 
        log_msg(LVL_DEBUG, "tcp_sock_close()");
 
533
        log_msg(LVL_DEBUG, "udp_sock_close()");
534
534
        socket_id = SOCKET_GET_SOCKET_ID(call);
535
535
 
536
536
        sock_core = socket_cores_find(&client->sockets, socket_id);
542
542
        socket = (udp_sockdata_t *)sock_core->specific_data;
543
543
        fibril_mutex_lock(&socket->lock);
544
544
 
 
545
        fibril_mutex_lock(&socket->recv_buffer_lock);
 
546
        log_msg(LVL_DEBUG, "udp_sock_close - set socket->sock_core = NULL");
 
547
        socket->sock_core = NULL;
 
548
        fibril_mutex_unlock(&socket->recv_buffer_lock);
 
549
 
 
550
        udp_uc_reset(socket->assoc);
 
551
 
545
552
        rc = socket_destroy(NULL, socket_id, &client->sockets, &gsock,
546
553
            udp_free_sock_data);
547
554
        if (rc != EOK) {
 
555
                log_msg(LVL_DEBUG, "udp_sock_close - socket_destroy failed");
548
556
                fibril_mutex_unlock(&socket->lock);
549
557
                async_answer_0(callid, rc);
550
558
                return;
551
559
        }
552
560
 
 
561
        log_msg(LVL_DEBUG, "udp_sock_close - broadcast recv_buffer_cv");
 
562
        fibril_condvar_broadcast(&socket->recv_buffer_cv);
 
563
 
553
564
        fibril_mutex_unlock(&socket->lock);
554
565
        async_answer_0(callid, EOK);
555
566
}
575
586
 
576
587
        log_msg(LVL_DEBUG, "udp_sock_recv_fibril()");
577
588
 
 
589
        fibril_mutex_lock(&sock->recv_buffer_lock);
 
590
 
578
591
        while (true) {
579
592
                log_msg(LVL_DEBUG, "[] wait for rcv buffer empty()");
580
 
                fibril_mutex_lock(&sock->recv_buffer_lock);
581
 
                while (sock->recv_buffer_used != 0) {
 
593
                while (sock->recv_buffer_used != 0 && sock->sock_core != NULL) {
582
594
                        fibril_condvar_wait(&sock->recv_buffer_cv,
583
595
                            &sock->recv_buffer_lock);
584
596
                }
588
600
                    UDP_FRAGMENT_SIZE, &rcvd, &xflags, &sock->recv_fsock);
589
601
                sock->recv_error = urc;
590
602
 
591
 
                udp_sock_notify_data(sock->sock_core);
 
603
                log_msg(LVL_DEBUG, "[] udp_uc_receive -> %d", urc);
 
604
 
 
605
                if (sock->sock_core != NULL)
 
606
                        udp_sock_notify_data(sock->sock_core);
592
607
 
593
608
                if (urc != UDP_EOK) {
 
609
                        log_msg(LVL_DEBUG, "[] urc != UDP_EOK, break");
594
610
                        fibril_condvar_broadcast(&sock->recv_buffer_cv);
595
 
                        fibril_mutex_unlock(&sock->recv_buffer_lock);
596
611
                        break;
597
612
                }
598
613
 
599
614
                log_msg(LVL_DEBUG, "[] got data - broadcast recv_buffer_cv");
600
615
 
601
616
                sock->recv_buffer_used = rcvd;
602
 
                fibril_mutex_unlock(&sock->recv_buffer_lock);
603
617
                fibril_condvar_broadcast(&sock->recv_buffer_cv);
604
618
        }
605
619
 
 
620
        log_msg(LVL_DEBUG, "udp_sock_recv_fibril() exited loop");
 
621
        fibril_mutex_unlock(&sock->recv_buffer_lock);
606
622
        udp_uc_destroy(sock->assoc);
607
623
 
 
624
        log_msg(LVL_DEBUG, "udp_sock_recv_fibril() terminated");
 
625
 
608
626
        return 0;
609
627
}
610
628