]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
replace para_connect() by PARA_CONNECT.
authorAndre Noll <maan@systemlinux.org>
Sat, 15 Sep 2007 17:42:29 +0000 (19:42 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 15 Sep 2007 17:42:29 +0000 (19:42 +0200)
PARA_CONNECT is a macro which works for all three socket address types
used in paraslash (sockaddr_in, sockaddr, sockaddr_un) and which does
not need a length parameter.

Change all instances of connect() and para_connect() to use PARA_CONNECT().

afs.c
audioc.c
audiod.c
client_common.c
dccp_recv.c
dccp_send.c
http_recv.c
net.c
net.h

diff --git a/afs.c b/afs.c
index 00aab24b745e16eb95cfeead62d4a4a2cdd7e867..0efb6991fe20b4d7e5aadd5585841cc39f739a5f 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -174,8 +174,8 @@ int send_callback_request(callback_function *f, struct osl_object *query,
        ret = init_unix_addr(&unix_addr, conf.afs_socket_arg);
        if (ret < 0)
                goto out;
        ret = init_unix_addr(&unix_addr, conf.afs_socket_arg);
        if (ret < 0)
                goto out;
-       ret = -E_CONNECT;
-       if (connect(fd, (struct sockaddr *)&unix_addr, sizeof(unix_addr)) < 0) /* FIXME: Use para_connect() */
+       ret = PARA_CONNECT(fd, &unix_addr);
+       if (ret < 0)
                goto out;
        ret = send_bin_buffer(fd, buf, sizeof(buf));
        if (ret < 0)
                goto out;
        ret = send_bin_buffer(fd, buf, sizeof(buf));
        if (ret < 0)
index d98ab46003c71912099d46b366fbdcaa294e77d5..15faebf1d49283123370a15521ee26e5dddc6ade 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -8,10 +8,10 @@
 
 #include "audioc.cmdline.h"
 #include "para.h"
 
 #include "audioc.cmdline.h"
 #include "para.h"
+#include "error.h"
 #include "net.h"
 #include "string.h"
 #include "fd.h"
 #include "net.h"
 #include "string.h"
 #include "fd.h"
-#include "error.h"
 
 INIT_AUDIOC_ERRLISTS;
 
 
 INIT_AUDIOC_ERRLISTS;
 
@@ -112,8 +112,8 @@ int main(int argc, char *argv[])
        ret = -E_INIT_SOCK_ADDR;
        if (init_unix_addr(&unix_addr, socket_name) < 0)
                goto out;
        ret = -E_INIT_SOCK_ADDR;
        if (init_unix_addr(&unix_addr, socket_name) < 0)
                goto out;
-       ret = -E_AUDIOC_CONNECT;
-       if (connect(fd, (struct sockaddr *)&unix_addr, UNIX_PATH_MAX) < 0) /* FIXME: Use para_connect() */
+       ret = PARA_CONNECT(fd, &unix_addr);
+       if (ret < 0)
                goto out;
        ret = send_cred_buffer(fd, args);
        if (ret < 0)
                goto out;
        ret = send_cred_buffer(fd, args);
        if (ret < 0)
index ccb233180e750b5077ba2cda6d2f622fd2cbad9b..5e0ff8d49f2dec598f1b87c64b1bf421dd9266a6 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -7,7 +7,7 @@
 /** \file audiod.c the paraslash's audio daemon */
 
 #include "para.h"
 /** \file audiod.c the paraslash's audio daemon */
 
 #include "para.h"
-
+#include "error.h"
 #include "audiod.cmdline.h"
 #include "list.h"
 #include "sched.h"
 #include "audiod.cmdline.h"
 #include "list.h"
 #include "sched.h"
@@ -24,7 +24,6 @@
 #include "fd.h"
 #include "write.h"
 #include "write_common.h"
 #include "fd.h"
 #include "write.h"
 #include "write_common.h"
-#include "error.h"
 #include "signal.h"
 
 /** define the array of error lists needed by para_audiod */
 #include "signal.h"
 
 /** define the array of error lists needed by para_audiod */
index 5a555469b52b213b42f756ab0bde32dfaee1b477..d950d2d744801c721b132cc13b45b10422faf289 100644 (file)
@@ -7,6 +7,7 @@
 /** \file client_common.c common functions of para_client and para_audiod */
 
 #include "para.h"
 /** \file client_common.c common functions of para_client and para_audiod */
 
 #include "para.h"
+#include "error.h"
 #include "list.h"
 #include "sched.h"
 #include "client.cmdline.h"
 #include "list.h"
 #include "sched.h"
 #include "client.cmdline.h"
@@ -17,7 +18,6 @@
 #include "string.h"
 #include "client.cmdline.h"
 #include "client.h"
 #include "string.h"
 #include "client.cmdline.h"
 #include "client.h"
-#include "error.h"
 
 /*
  * rc4 encrypt data before sending
 
 /*
  * rc4 encrypt data before sending
@@ -90,7 +90,7 @@ static int client_connect(struct private_client_data *pcd)
        pcd->fd = ret;
        /* init their_addr */
        init_sockaddr(&their_addr, pcd->conf.server_port_arg, he);
        pcd->fd = ret;
        /* init their_addr */
        init_sockaddr(&their_addr, pcd->conf.server_port_arg, he);
-       ret = para_connect(pcd->fd, &their_addr);
+       ret = PARA_CONNECT(pcd->fd, &their_addr);
        if (ret < 0)
                goto err_out;
        pcd->status = CL_CONNECTED;
        if (ret < 0)
                goto err_out;
        pcd->status = CL_CONNECTED;
index f113968346e19c136fad2d764e8a1a1b31422c7d..2f946fc61726e07a36853ee4ad2c2784776964f9 100644 (file)
@@ -83,7 +83,7 @@ static int dccp_recv_open(struct receiver_node *rn)
        if (ret < 0)
                goto err_out;
        PARA_NOTICE_LOG("connecting to %s:%d\n", conf->host_arg, conf->port_arg);
        if (ret < 0)
                goto err_out;
        PARA_NOTICE_LOG("connecting to %s:%d\n", conf->host_arg, conf->port_arg);
-       ret = connect(pdd->fd, ai->ai_addr, ai->ai_addrlen);
+       ret = PARA_CONNECT(pdd->fd, ai->ai_addr);
        freeaddrinfo(ai);
        if (ret < 0) {
                ret = -E_DCCP_CONNECT;
        freeaddrinfo(ai);
        if (ret < 0) {
                ret = -E_DCCP_CONNECT;
index 4394b33bf2c5707f1895716de490c3bafda12ece..3509d5d88a5e18f00089885ae7be41b8207e1b17 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include "para.h"
  */
 
 #include "para.h"
+#include "error.h"
 #include "afh.h"
 #include "server.h"
 #include "net.h"
 #include "afh.h"
 #include "server.h"
 #include "net.h"
@@ -19,7 +20,6 @@
 #include "vss.h"
 #include "send.h"
 #include "dccp.h"
 #include "vss.h"
 #include "send.h"
 #include "dccp.h"
-#include "error.h"
 #include "string.h"
 #include "fd.h"
 #include "close_on_fork.h"
 #include "string.h"
 #include "fd.h"
 #include "close_on_fork.h"
index 05f452e6d02160ad33914ec96e0abbb48e696593..f82924d9cfd728c83f4bed516fc4e84dbe21e139 100644 (file)
@@ -7,13 +7,12 @@
 /** \file http_recv.c paraslash's http receiver */
 
 #include "para.h"
 /** \file http_recv.c paraslash's http receiver */
 
 #include "para.h"
-
+#include "error.h"
 #include "http.h"
 #include "list.h"
 #include "sched.h"
 #include "recv.h"
 #include "http_recv.cmdline.h"
 #include "http.h"
 #include "list.h"
 #include "sched.h"
 #include "recv.h"
 #include "http_recv.cmdline.h"
-#include "error.h"
 #include "net.h"
 #include "string.h"
 #include "fd.h"
 #include "net.h"
 #include "string.h"
 #include "fd.h"
@@ -181,10 +180,9 @@ static int http_recv_open(struct receiver_node *rn)
        phd->fd = ret;
        /* init their_addr */
        init_sockaddr(&their_addr, conf->port_arg, he);
        phd->fd = ret;
        /* init their_addr */
        init_sockaddr(&their_addr, conf->port_arg, he);
-       /* connect */
        PARA_NOTICE_LOG("connecting to %s:%d\n", conf->host_arg,
                conf->port_arg);
        PARA_NOTICE_LOG("connecting to %s:%d\n", conf->host_arg,
                conf->port_arg);
-       ret = para_connect(phd->fd, &their_addr);
+       ret = PARA_CONNECT(phd->fd, &their_addr);
        if (ret < 0) {
                close(phd->fd);
                goto err_out;
        if (ret < 0) {
                close(phd->fd);
                goto err_out;
diff --git a/net.c b/net.c
index 3dcd9c0be5884f59293d012c3e117ea61b83a282..221ad89074226753f58832052a0ccf08103724e8 100644 (file)
--- a/net.c
+++ b/net.c
@@ -6,10 +6,10 @@
 
 /** \file net.c networking-related helper functions */
 
 
 /** \file net.c networking-related helper functions */
 
+#include "error.h"
 #include "para.h"
 #include "net.h"
 #include "string.h"
 #include "para.h"
 #include "net.h"
 #include "string.h"
-#include "error.h"
 
 
 /** Information about one encrypted connection. */
 
 
 /** Information about one encrypted connection. */
@@ -302,26 +302,6 @@ int get_stream_socket(int domain)
        return socket_fd;
 }
 
        return socket_fd;
 }
 
-/**
- * a wrapper around connect(2)
- *
- * \param fd the file descriptor
- * \param their_addr the address to connect
- *
- * \return \p -E_CONNECT on errors, 1 on success
- *
- * \sa connect(2)
- */
-int para_connect(int fd, struct sockaddr_in *their_addr)
-{
-       int ret;
-
-       if ((ret = connect(fd, (struct sockaddr *)their_addr,
-                       sizeof(struct sockaddr))) == -1)
-               return -E_CONNECT;
-       return 1;
-}
-
 /**
  * paraslash's wrapper around the accept system call
  *
 /**
  * paraslash's wrapper around the accept system call
  *
diff --git a/net.h b/net.h
index ddc250952bd9592e0e7195518559528f3be65138..8fdaa3eebf0285dc490470186093fbe8f4529ebe 100644 (file)
--- a/net.h
+++ b/net.h
@@ -24,7 +24,6 @@ typedef void crypt_function(unsigned long len,
 int get_host_info(char *host, struct hostent **ret);
 int get_stream_socket(int domain);
 void init_sockaddr(struct sockaddr_in*, int, const struct hostent*);
 int get_host_info(char *host, struct hostent **ret);
 int get_stream_socket(int domain);
 void init_sockaddr(struct sockaddr_in*, int, const struct hostent*);
-int para_connect(int fd, struct sockaddr_in *their_addr);
 int send_buffer(int, const char *);
 int send_bin_buffer(int, const char *, size_t);
 __printf_2_3 int send_va_buffer(int fd, const char *fmt, ...);
 int send_buffer(int, const char *);
 int send_bin_buffer(int, const char *, size_t);
 __printf_2_3 int send_va_buffer(int fd, const char *fmt, ...);
@@ -42,3 +41,24 @@ void enable_crypt(int fd, crypt_function *recv_f, crypt_function *send_f,
        void *private_data);
 void disable_crypt(int fd);
 
        void *private_data);
 void disable_crypt(int fd);
 
+/**
+ * A wrapper around connect(2).
+ *
+ * \param fd The file descriptor.
+ * \param their_addr The address to connect.
+ *
+ * This should not be called directly. Always use the PARA_CONNECT macro.
+ *
+ * \return \p -E_CONNECT on errors, 1 on success.
+ *
+ * \sa connect(2), PARA_CONNECT.
+ */
+_static_inline_ int _para_connect(int fd, void *addr, socklen_t len)
+{
+       if (connect(fd, (struct sockaddr *)addr, len) == -1)
+               return -E_CONNECT;
+       return 1;
+}
+
+/** A macro for connect() which does not need a \a len parameter. */
+#define PARA_CONNECT(fd, addr) _para_connect(fd, addr, sizeof(*(addr)))