unlock and close cachefile if we bail out of socket creation.
[trinity.git] / net / proto-rds.c
blob5254740464b7f08e6a69ff399791be07692e3d7c
1 #include <stdlib.h>
2 #include "net.h"
3 #include "config.h"
5 #define SOL_RDS 276
7 #ifdef USE_RDS
8 #include <linux/rds.h>
9 #endif
11 #include "compat.h"
12 #include "utils.h" // ARRAY_SIZE
14 void rds_rand_socket(struct socket_triplet *st)
16 st->protocol = 0;
17 st->type = SOCK_SEQPACKET;
20 void rds_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen)
22 struct sockaddr_in *rds;
24 rds = malloc(sizeof(struct sockaddr_in));
25 if (rds == NULL)
26 return;
27 rds->sin_family = AF_INET;
28 rds->sin_addr.s_addr = random_ipv4_address();
29 rds->sin_port = rand() % 65535;
31 *addr = (struct sockaddr *) rds;
32 *addrlen = sizeof(struct sockaddr_in);
35 #ifdef USE_RDS
36 static const unsigned int rds_opts[] = {
37 RDS_CANCEL_SENT_TO, RDS_GET_MR, RDS_FREE_MR,
38 4, /* deprecated RDS_BARRIER 4 */
39 RDS_RECVERR, RDS_CONG_MONITOR, RDS_GET_MR_FOR_DEST };
40 #define NR_SOL_RDS_OPTS ARRAY_SIZE(rds_opts)
42 void rds_setsockopt(struct sockopt *so)
44 unsigned char val;
46 so->level = SOL_RDS;
48 val = rand() % NR_SOL_RDS_OPTS;
49 so->optname = rds_opts[val];
52 #else
53 /* stub if we are built on something without RDS headers */
54 void rds_setsockopt(struct sockopt *so)
56 so->level = SOL_RDS;
58 #endif /* USE_RDS */