Merge branch 'maint'
[paraslash.git] / dccp_recv.c
index 0a7b3c069271329152f131afa1f1334416473d10..f71a7253a0296e8c0f849147287b5cede93233e0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2009 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2006-2010 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -57,11 +57,25 @@ static int dccp_recv_open(struct receiver_node *rn)
 {
        struct private_dccp_recv_data *pdd;
        struct dccp_recv_args_info *conf = rn->conf;
-       int fd, ret = para_connect_simple(IPPROTO_DCCP, conf->host_arg,
-                                                       conf->port_arg);
-       if (ret < 0)
-               return ret;
-       fd = ret;
+       struct flowopts *fo = NULL;
+       uint8_t *ccids = NULL;
+       int fd, ret, i;
+
+       /* Copy CCID preference list (u8 array required) */
+       if (conf->ccid_given) {
+               ccids = para_malloc(conf->ccid_given);
+               fo    = flowopt_new();
+
+               for (i = 0; i < conf->ccid_given; i++)
+                       ccids[i] = conf->ccid_arg[i];
+
+               OPT_ADD(fo, SOL_DCCP, DCCP_SOCKOPT_CCID, ccids, i);
+       }
+
+       fd = makesock(IPPROTO_DCCP, 0, conf->host_arg, conf->port_arg, fo);
+       free(ccids);
+       if (fd < 0)
+               return fd;
        /*
         * Disable unused CCIDs: the receiver does not send any application
         * data to the server. By shutting down this unused path we reduce
@@ -84,11 +98,38 @@ err:
        return ret;
 }
 
+/**
+ * Check whether the host supports the requested 'ccid' arguments.
+ * \param conf DCCP receiver arguments.
+ * \return True if all CCIDs requested in \a conf are supported.
+ */
+static bool dccp_recv_ccid_support_check(struct dccp_recv_args_info *conf)
+{
+       uint8_t *ccids;
+       int i, j, nccids;
+
+       nccids = dccp_available_ccids(&ccids);
+       if (nccids <= 0)
+               return false;
+
+       for (i = 0; i < conf->ccid_given; i++) {
+               for (j = 0; j < nccids && ccids[j] != conf->ccid_arg[i]; j++)
+                       ;
+               if (j == nccids) {
+                       PARA_ERROR_LOG("'CCID-%d' not supported on this host.\n",
+                                       conf->ccid_arg[i]);
+                       return false;
+               }
+       }
+       return true;
+}
+
 static void *dccp_recv_parse_config(int argc, char **argv)
 {
-       struct dccp_recv_args_info *tmp = para_calloc(sizeof(struct dccp_recv_args_info));
+       struct dccp_recv_args_info *tmp = para_calloc(sizeof(*tmp));
 
-       if (!dccp_recv_cmdline_parser(argc, argv, tmp))
+       if (!dccp_recv_cmdline_parser(argc, argv, tmp) &&
+           dccp_recv_ccid_support_check(tmp))
                return tmp;
        free(tmp);
        return NULL;
@@ -125,6 +166,9 @@ static void dccp_recv_post_select(struct sched *s, struct task *t)
        if (iovcnt == 0)
                goto err;
        ret = para_readv(pdd->fd, iov, iovcnt);
+       /* EAGAIN is possible even if FD_ISSET */
+       if (ret < 0 && is_errno(-ret, EAGAIN))
+               return;
        if (ret == 0)
                ret = -E_RECV_EOF;
        if (ret < 0)