From: Andre Noll Date: Tue, 6 Dec 2011 20:07:56 +0000 (+0100) Subject: Move send_buffer() and send_va_buffer() from net.c to fd.c. X-Git-Tag: v0.4.10~11^2~10 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=748d1368bc96dd7e1af879df1ea41b4d52842f7e;p=paraslash.git Move send_buffer() and send_va_buffer() from net.c to fd.c. These functions end up calling plain write(), hence they work on arbitrary file descriptors, not just network sockets. So they really belong to fd.c rather than to net.c. Rename the two functions to write_buffer() and write_va_buffer(). --- diff --git a/client_common.c b/client_common.c index 5ac1cdb7..5bd2241b 100644 --- a/client_common.c +++ b/client_common.c @@ -188,7 +188,7 @@ static void client_post_select(struct sched *s, struct task *t) PARA_INFO_LOG("--> %s\n", buf); if (!FD_ISSET(ct->scc.fd, &s->wfds)) return; - ret = send_buffer(ct->scc.fd, buf); + ret = write_buffer(ct->scc.fd, buf); if (ret < 0) goto out; ct->status = CL_SENT_AUTH; diff --git a/command.c b/command.c index e344e77a..4aa262ce 100644 --- a/command.c +++ b/command.c @@ -750,7 +750,7 @@ __noreturn void handle_connect(int fd, const char *peername) if (ret < 0) goto net_err; /* send Welcome message */ - ret = send_va_buffer(fd, "This is para_server, version " + ret = write_va_buffer(fd, "This is para_server, version " PACKAGE_VERSION ".\n" ); if (ret < 0) goto net_err; diff --git a/fd.c b/fd.c index 429960cc..6f487c41 100644 --- a/fd.c +++ b/fd.c @@ -42,6 +42,25 @@ int write_all(int fd, const char *buf, size_t len) return len; } +/** + * Send a buffer given by a format string. + * + * \param fd The file descriptor. + * \param fmt A format string. + * + * \return Standard. + */ +__printf_2_3 int write_va_buffer(int fd, const char *fmt, ...) +{ + char *msg; + int ret; + + PARA_VSPRINTF(fmt, msg); + ret = write_buffer(fd, msg); + free(msg); + return ret; +} + /** * Write a buffer to a non-blocking file descriptor. * diff --git a/fd.h b/fd.h index b12067ec..ed4c85a5 100644 --- a/fd.h +++ b/fd.h @@ -7,6 +7,7 @@ /** \file fd.h exported symbols from fd.c */ int write_all(int fd, const char *buf, size_t len); +__printf_2_3 int write_va_buffer(int fd, const char *fmt, ...); int file_exists(const char *); int para_select(int n, fd_set *readfds, fd_set *writefds, struct timeval *timeout_tv); @@ -31,3 +32,17 @@ int read_pattern(int fd, const char *pattern, size_t bufsize, fd_set *rfds); int write_nonblock(int fd, const char *buf, size_t len); int for_each_file_in_dir(const char *dirname, int (*func)(const char *, void *), void *private_data); +/** + * Write a \p NULL-terminated buffer. + * + * \param fd The file descriptor. + * \param buf The null-terminated buffer to be send. + * + * This is equivalent to write_all(fd, buf, strlen(buf)). + * + * \return Standard. + */ +_static_inline_ int write_buffer(int fd, const char *buf) +{ + return write_all(fd, buf, strlen(buf)); +} diff --git a/http_recv.c b/http_recv.c index 350f410d..c3d918c5 100644 --- a/http_recv.c +++ b/http_recv.c @@ -95,7 +95,7 @@ static void http_recv_post_select(struct sched *s, struct task *t) return; rq = make_request_msg(); PARA_INFO_LOG("sending http request\n"); - ret = send_va_buffer(rn->fd, "%s", rq); + ret = write_va_buffer(rn->fd, "%s", rq); free(rq); if (ret < 0) goto out; diff --git a/http_send.c b/http_send.c index 8b705d0d..c26572f0 100644 --- a/http_send.c +++ b/http_send.c @@ -53,7 +53,7 @@ static struct sender_status http_sender_status, *hss = &http_sender_status; static int http_send_msg(struct sender_client *sc, const char *msg) { - int ret = send_buffer(sc->fd, msg); + int ret = write_buffer(sc->fd, msg); if (ret < 0) shutdown_client(sc, hss); diff --git a/net.c b/net.c index 9c300c74..92b43065 100644 --- a/net.c +++ b/net.c @@ -689,40 +689,6 @@ struct in_addr extract_v4_addr(const struct sockaddr_storage *ss) return ia; } -/** - * Send a \p NULL-terminated buffer. - * - * \param fd The file descriptor. - * \param buf The null-terminated buffer to be send. - * - * This is equivalent to write_all(fd, buf, strlen(buf)). - * - * \return Standard. - */ -int send_buffer(int fd, const char *buf) -{ - return write_all(fd, buf, strlen(buf)); -} - -/** - * Send a buffer given by a format string. - * - * \param fd The file descriptor. - * \param fmt A format string. - * - * \return Standard. - */ -__printf_2_3 int send_va_buffer(int fd, const char *fmt, ...) -{ - char *msg; - int ret; - - PARA_VSPRINTF(fmt, msg); - ret = send_buffer(fd, msg); - free(msg); - return ret; -} - /** * Receive data from a file descriptor. * @@ -943,7 +909,7 @@ err: #ifndef HAVE_UCRED ssize_t send_cred_buffer(int sock, char *buf) { - return send_buffer(sock, buf); + return write_buffer(sock, buf); } int recv_cred_buffer(int fd, char *buf, size_t size) { diff --git a/net.h b/net.h index fb7faa3c..a3ff49e9 100644 --- a/net.h +++ b/net.h @@ -141,9 +141,6 @@ extern char *remote_name(int sockfd); */ extern int generic_max_transport_msg_size(int sockfd); -int send_buffer(int, const char *); -__printf_2_3 int send_va_buffer(int fd, const char *fmt, ...); - int recv_bin_buffer(int fd, char *buf, size_t size); int recv_buffer(int fd, char *buf, size_t size); diff --git a/vss.c b/vss.c index bfea37a1..8f177bab 100644 --- a/vss.c +++ b/vss.c @@ -1136,7 +1136,7 @@ static void vss_post_select(struct sched *s, struct task *t) recv_afs_result(vsst, &s->rfds); else if (FD_ISSET(vsst->afs_socket, &s->wfds)) { PARA_NOTICE_LOG("requesting new fd from afs\n"); - ret = send_buffer(vsst->afs_socket, "new"); + ret = write_buffer(vsst->afs_socket, "new"); if (ret < 0) PARA_CRIT_LOG("%s\n", para_strerror(-ret)); else