From 7a8d90c41b758d1c3ae8530a44ccd9aaa857581e Mon Sep 17 00:00:00 2001 From: Gerrit Renker Date: Fri, 30 Nov 2007 10:23:51 +0100 Subject: [PATCH] 04_DCCP-socket-functions.diff This converts the DCCP streaming unit to use the makesock interface. As much as possible, the format of the system calls was modelled after / adapted to that of the HTTP sender/receiver. This includes the use of a `name' field for the remote socket name of the connecting client. Signed-off-by: Gerrit Renker --- dccp_recv.c | 40 ++++++---------------------------------- dccp_send.c | 36 +++++++++--------------------------- error.h | 4 ---- 3 files changed, 15 insertions(+), 65 deletions(-) diff --git a/dccp_recv.c b/dccp_recv.c index f0d7d66e..5329852d 100644 --- a/dccp_recv.c +++ b/dccp_recv.c @@ -26,11 +26,6 @@ #include "dccp_recv.cmdline.h" -/* needed by getaddrinfo */ -#include -#include -#include - /** the size of the output buffer */ #define DCCP_BUFSIZE 40960 @@ -63,40 +58,17 @@ static int dccp_recv_open(struct receiver_node *rn) { struct private_dccp_recv_data *pdd; struct dccp_recv_args_info *conf = rn->conf; - int ret; - struct addrinfo *ai; - char *tmp; + int ret = makesock(AF_UNSPEC, IPPROTO_DCCP, 0, conf->host_arg, conf->port_arg); - rn->buf = para_calloc(DCCP_BUFSIZE); - rn->private_data = para_calloc(sizeof(struct private_dccp_recv_data)); - pdd = rn->private_data; - ret = dccp_get_socket(); if (ret < 0) - goto err_out; - pdd->fd = ret; + return ret; - tmp = make_message("%d", conf->port_arg); - ret = getaddrinfo(conf->host_arg, tmp, NULL, &ai); - free(tmp); - if (ret) { - ret = -E_ADDR_INFO; - goto err_out; - } - ret = dccp_set_socket(pdd->fd); - if (ret < 0) - goto err_out; - PARA_NOTICE_LOG("connecting to %s:%d\n", conf->host_arg, conf->port_arg); - ret = PARA_CONNECT(pdd->fd, ai->ai_addr); - freeaddrinfo(ai); - if (ret < 0) { - ret = -E_DCCP_CONNECT; - goto err_out; - } + rn->buf = para_calloc(DCCP_BUFSIZE); + rn->private_data = pdd = para_calloc(sizeof(struct private_dccp_recv_data)); + + pdd->fd = ret; mark_fd_nonblocking(pdd->fd); return 1; -err_out: - dccp_recv_close(rn); - return ret; } static void dccp_shutdown(void) diff --git a/dccp_send.c b/dccp_send.c index 27623237..0310584d 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -42,8 +42,8 @@ static struct sender *self; struct dccp_client { /** the dccp socket */ int fd; - /** address information about the client */ - struct sockaddr_in addr; + /** The socket `name' of the client. */ + char *name; /** the position of this client in the client list */ struct list_head node; /** non-zero if audio file header has been sent */ @@ -68,14 +68,15 @@ static void dccp_post_select(fd_set *rfds, __a_unused fd_set *wfds) if (!FD_ISSET(listen_fd, rfds)) return; - dc = para_calloc(sizeof(struct dccp_client)); - ret = para_accept(listen_fd, &dc->addr, sizeof(struct sockaddr_in)); + ret = para_accept(listen_fd, NULL, 0); if (ret < 0) { PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); return; } - PARA_NOTICE_LOG("connection from %s\n", inet_ntoa(dc->addr.sin_addr)); + dc = para_calloc(sizeof(struct dccp_client)); dc->fd = ret; + dc->name = make_message("%s", remote_name(dc->fd)); + PARA_NOTICE_LOG("connection from %s\n", dc->name); para_list_add(&dc->node, &clients); add_close_on_fork_list(dc->fd); mark_fd_nonblocking(dc->fd); @@ -84,30 +85,11 @@ static void dccp_post_select(fd_set *rfds, __a_unused fd_set *wfds) static int dccp_open(void) { - struct sockaddr_in servaddr; - int ret; + int ret = para_listen(AF_UNSPEC, IPPROTO_DCCP, conf.dccp_port_arg); - ret = dccp_get_socket(); if (ret < 0) return ret; listen_fd = ret; - - memset(&servaddr, 0, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); - servaddr.sin_port = htons(conf.dccp_port_arg); - ret = bind(listen_fd, (struct sockaddr *)&servaddr, sizeof(servaddr)); - if (ret < 0) - return -E_DCCP_BIND; - ret = dccp_set_socket(listen_fd); - if (ret < 0) - return ret; - ret = listen(listen_fd, 0); - if (ret < 0) { - PARA_ERROR_LOG("%s\n", strerror(errno)); - return -E_DCCP_LISTEN; - } - PARA_DEBUG_LOG("listening on fd %d\n", listen_fd); add_close_on_fork_list(listen_fd); mark_fd_nonblocking(listen_fd); return 1; @@ -115,8 +97,8 @@ static int dccp_open(void) static void dccp_shutdown_client(struct dccp_client *dc) { - PARA_DEBUG_LOG("shutting down %s (fd %d)\n", inet_ntoa(dc->addr.sin_addr), - dc->fd); + PARA_DEBUG_LOG("shutting down %s (fd %d)\n", dc->name, dc->fd); + free(dc->name); close(dc->fd); del_close_on_fork_list(dc->fd); cq_destroy(dc->cq); diff --git a/error.h b/error.h index fada9b30..534e7f97 100644 --- a/error.h +++ b/error.h @@ -355,15 +355,11 @@ extern const char **para_errlist[]; #define DCCP_RECV_ERRORS \ - PARA_ERROR(ADDR_INFO, "getaddrinfo error"), \ PARA_ERROR(DCCP_OVERRUN, "dccp output buffer buffer overrun"), \ - PARA_ERROR(DCCP_CONNECT, "dccp connect error"), \ PARA_ERROR(DCCP_RECV_EOF, "dccp_recv: end of file"), \ #define DCCP_SEND_ERRORS \ - PARA_ERROR(DCCP_BIND, "dccp bind error"), \ - PARA_ERROR(DCCP_LISTEN, "dccp listen error"), \ PARA_ERROR(DCCP_WRITE, "dccp write error"), \ -- 2.39.5