]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Move send_buffer() and send_va_buffer() from net.c to fd.c.
authorAndre Noll <maan@systemlinux.org>
Tue, 6 Dec 2011 20:07:56 +0000 (21:07 +0100)
committerAndre Noll <maan@systemlinux.org>
Fri, 20 Jan 2012 21:57:06 +0000 (22:57 +0100)
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().

client_common.c
command.c
fd.c
fd.h
http_recv.c
http_send.c
net.c
net.h
vss.c

index 5ac1cdb77ced80efe804c7017d9f4ec7a03bc940..5bd2241b8d933fb69309560d5b2056ed6438cdd9 100644 (file)
@@ -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;
index e344e77acc6bf3c4867ff8e0f3f5c6f1dafb3f4a..4aa262ce36f2f07c026e8453bfc2364f4684884f 100644 (file)
--- 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 429960cc0ab3d822811a1702c56c99a9e4c1ff10..6f487c410020795a73476fa79ba552c2ad29e4fd 100644 (file)
--- 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 b12067ec404976f9c6f96345c1a4bd4b21cb2d13..ed4c85a59480b97f6c15876b8b5f5de96c88a614 100644 (file)
--- 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));
+}
index 350f410dccd18886872b63787f1c280709f3d223..c3d918c51ab37069c05f879a2492b38d1ce6fd4d 100644 (file)
@@ -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;
index 8b705d0d156b65f57caab561163b32c65fb77c92..c26572f024557fc4f206835a7e93f24cf59d0231 100644 (file)
@@ -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 9c300c744c11ddbec362eb02433a6a3d60db8163..92b43065ba4363c9d7ef4099303fd1074ca16f1e 100644 (file)
--- 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 fb7faa3ced21da31e38d904d1fb51d458166bdec..a3ff49e950e57e98a885c49e57581d4e485d369f 100644 (file)
--- 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 bfea37a191f8b90db60db720916eb37ebf900223..8f177bab56b90a221f4ac84b73e4c54971df4a0c 100644 (file)
--- 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