7 /*----- for all comms -----*/
9 struct comm_notify_entry {
12 LIST_ENTRY(comm_notify_entry) entry;
14 LIST_HEAD(comm_notify_list, comm_notify_entry) notify;
16 struct commcommon { /* must be first so that void* is comm_common* */
20 struct comm_notify_list notify;
21 struct buffer_if *rbuf;
24 void comm_request_notify(void *commst, void *nst, comm_notify_fn *fn);
25 void comm_release_notify(void *commst, void *nst, comm_notify_fn *fn);
27 bool_t comm_notify(struct comm_notify_list *notify, struct buffer_if *buf,
28 const struct comm_addr *ca);
29 /* Either: returns True, with message delivered and buffer freed.
30 * Or: False, if no-one wanted it - buffer still allocd'd.
31 * Ie, like comm_notify_fn. */
33 void comm_apply(struct commcommon *cc);
35 #define COMM_APPLY(st,cc,prefix,desc,loc) \
36 (st)=safe_malloc(sizeof(*(st)), desc "_apply"); \
38 (cc)->cl.description=desc; \
39 (cc)->ops.sendmsg=prefix##sendmsg; \
40 (cc)->ops.addr_to_string=prefix##addr_to_string; \
42 /* Expects in scope: prefix##sendmsg, prefix##addr_to_string. */
44 #define COMM_APPLY_STANDARD(st,cc,desc,args) \
45 item_t *item=list_elem(args,0); \
46 if (!item || item->type!=t_dict) { \
47 cfgfatal((cc)->loc,desc,"first argument must be a dictionary\n"); \
49 dict_t *d=item->data.dict; \
50 (cc)->rbuf=find_cl_if(d,"buffer",CL_BUFFER,True,desc,(cc)->loc)
52 /*----- for udp-based comms -----*/
54 #define UDP_MAX_SOCKETS 3 /* 2 ought to do really */
56 #define MAX_AF (AF_INET6>AF_INET?AF_INET6:AF_INET)
61 bool_t experienced[/*0=recv,1=send*/2][MAX_AF+1][/*success?*/2];
66 struct udpsock socks[UDP_MAX_SOCKETS];
67 /* private for udp_socks_* */
68 struct udpcommon *uc; /* link to parent, for cfg, notify list, etc. */
69 struct poll_interest *interest;
81 bool_t udp_make_socket(struct udpcommon *uc, struct udpsock *us,
83 /* Caller should have filled in ->addr. Fills in us->fd,
84 ->experienced; updates ->addr. Logs any errors with lg_[v]perror. */
85 bool_t udp_import_socket(struct udpcommon *uc, struct udpsock *us,
86 int failmsgclass, int fd);
87 /* Like udp_make_socket, but caller provides fd. fd is not closed
90 void udp_destroy_socket(struct udpcommon *uc, struct udpsock *us);
91 /* Idempotent. No errors are possible. */
93 const char *af_name(int af);
94 void udp_sock_experienced(struct log_if *lg, struct udpcommon *uc,
95 struct udpsocks *socks, struct udpsock *us,
96 bool_t recvsend, int af /* 0 means any */,
99 void udp_socks_register(struct udpcommon *uc, struct udpsocks *socks,
101 void udp_socks_deregister(struct udpcommon *uc, struct udpsocks *socks);
102 void udp_socks_childpersist(struct udpcommon *uc, struct udpsocks *socks);
104 #define UDP_APPLY_STANDARD(st,uc,desc) \
105 (uc)->use_proxy=False; \
106 (uc)->authbind=NULL; \
107 (uc)->port=dict_read_number(d,"port",False,"udp",(uc)->cc.loc,0)
108 /* Expects in scope: dict_t *d=...; */
110 #endif /*COMM_COMMON_H*/