Mercurial > hg > freeDiameter
comparison libfdcore/p_out.c @ 1186:56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Fri, 07 Jun 2013 18:48:34 +0800 |
parents | 79dd22145f52 |
children | 043b894b0511 |
comparison
equal
deleted
inserted
replaced
1185:23695957bfc0 | 1186:56c36d1007b4 |
---|---|
34 *********************************************************************************************************/ | 34 *********************************************************************************************************/ |
35 | 35 |
36 #include "fdcore-internal.h" | 36 #include "fdcore-internal.h" |
37 | 37 |
38 /* Alloc a new hbh for requests, bufferize the message and send on the connection, save in sentreq if provided */ | 38 /* Alloc a new hbh for requests, bufferize the message and send on the connection, save in sentreq if provided */ |
39 static int do_send(struct msg ** msg, uint32_t flags, struct cnxctx * cnx, uint32_t * hbh, struct fd_peer * peer) | 39 static int do_send(struct msg ** msg, struct cnxctx * cnx, uint32_t * hbh, struct fd_peer * peer) |
40 { | 40 { |
41 struct msg_hdr * hdr; | 41 struct msg_hdr * hdr; |
42 int msg_is_a_req; | 42 int msg_is_a_req; |
43 uint8_t * buf; | 43 uint8_t * buf; |
44 size_t sz; | 44 size_t sz; |
45 int ret; | 45 int ret; |
46 uint32_t bkp_hbh = 0; | 46 uint32_t bkp_hbh = 0; |
47 struct msg *cpy_for_logs_only; | 47 struct msg *cpy_for_logs_only; |
48 | 48 |
49 TRACE_ENTRY("%p %x %p %p %p", msg, flags, cnx, hbh, peer); | 49 TRACE_ENTRY("%p %p %p %p", msg, cnx, hbh, peer); |
50 | 50 |
51 /* Retrieve the message header */ | 51 /* Retrieve the message header */ |
52 CHECK_FCT( fd_msg_hdr(*msg, &hdr) ); | 52 CHECK_FCT( fd_msg_hdr(*msg, &hdr) ); |
53 | 53 |
54 msg_is_a_req = (hdr->msg_flags & CMD_FLAG_REQUEST); | 54 msg_is_a_req = (hdr->msg_flags & CMD_FLAG_REQUEST); |
73 | 73 |
74 /* Log the message */ | 74 /* Log the message */ |
75 fd_hook_call(HOOK_MESSAGE_SENT, cpy_for_logs_only, peer, NULL, fd_msg_pmdl_get(cpy_for_logs_only)); | 75 fd_hook_call(HOOK_MESSAGE_SENT, cpy_for_logs_only, peer, NULL, fd_msg_pmdl_get(cpy_for_logs_only)); |
76 | 76 |
77 /* Send the message */ | 77 /* Send the message */ |
78 CHECK_FCT_DO( ret = fd_cnx_send(cnx, buf, sz, flags), ); | 78 CHECK_FCT_DO( ret = fd_cnx_send(cnx, buf, sz), ); |
79 out: | 79 out: |
80 ; | 80 ; |
81 pthread_cleanup_pop(1); | 81 pthread_cleanup_pop(1); |
82 | 82 |
83 if (ret) | 83 if (ret) |
125 | 125 |
126 /* Now if we are cancelled, we requeue this message */ | 126 /* Now if we are cancelled, we requeue this message */ |
127 pthread_cleanup_push(cleanup_requeue, msg); | 127 pthread_cleanup_push(cleanup_requeue, msg); |
128 | 128 |
129 /* Send the message, log any error */ | 129 /* Send the message, log any error */ |
130 CHECK_FCT_DO( ret = do_send(&msg, 0, peer->p_cnxctx, &peer->p_hbh, peer), | 130 CHECK_FCT_DO( ret = do_send(&msg, peer->p_cnxctx, &peer->p_hbh, peer), |
131 { | 131 { |
132 if (msg) { | 132 if (msg) { |
133 char buf[256]; | 133 char buf[256]; |
134 snprintf(buf, sizeof(buf), "Error while sending this message: %s", strerror(ret)); | 134 snprintf(buf, sizeof(buf), "Error while sending this message: %s", strerror(ret)); |
135 fd_hook_call(HOOK_MESSAGE_DROPPED, msg, NULL, buf, fd_msg_pmdl_get(msg)); | 135 fd_hook_call(HOOK_MESSAGE_DROPPED, msg, NULL, buf, fd_msg_pmdl_get(msg)); |
146 CHECK_FCT_DO( fd_event_send(peer->p_events, FDEVP_CNX_ERROR, 0, NULL), /* What do we do if it fails? */ ); | 146 CHECK_FCT_DO( fd_event_send(peer->p_events, FDEVP_CNX_ERROR, 0, NULL), /* What do we do if it fails? */ ); |
147 return NULL; | 147 return NULL; |
148 } | 148 } |
149 | 149 |
150 /* Wrapper to sending a message either by out thread (peer in OPEN state) or directly; cnx or peer must be provided. Flags are valid only for direct sending, not through thread (unused) */ | 150 /* Wrapper to sending a message either by out thread (peer in OPEN state) or directly; cnx or peer must be provided. Flags are valid only for direct sending, not through thread (unused) */ |
151 int fd_out_send(struct msg ** msg, struct cnxctx * cnx, struct fd_peer * peer, uint32_t flags) | 151 int fd_out_send(struct msg ** msg, struct cnxctx * cnx, struct fd_peer * peer) |
152 { | 152 { |
153 struct msg_hdr * hdr; | 153 struct msg_hdr * hdr; |
154 | 154 |
155 TRACE_ENTRY("%p %p %p %x", msg, cnx, peer, flags); | 155 TRACE_ENTRY("%p %p %p", msg, cnx, peer); |
156 CHECK_PARAMS( msg && *msg && (cnx || (peer && peer->p_cnxctx))); | 156 CHECK_PARAMS( msg && *msg && (cnx || (peer && peer->p_cnxctx))); |
157 | 157 |
158 if (peer) { | 158 if (peer) { |
159 CHECK_FCT( fd_msg_hdr(*msg, &hdr) ); | 159 CHECK_FCT( fd_msg_hdr(*msg, &hdr) ); |
160 if (!(hdr->msg_flags & CMD_FLAG_REQUEST)) { | 160 if (!(hdr->msg_flags & CMD_FLAG_REQUEST)) { |
179 | 179 |
180 if (!cnx) | 180 if (!cnx) |
181 cnx = peer->p_cnxctx; | 181 cnx = peer->p_cnxctx; |
182 | 182 |
183 /* Do send the message */ | 183 /* Do send the message */ |
184 CHECK_FCT_DO( ret = do_send(msg, flags, cnx, hbh, peer), | 184 CHECK_FCT_DO( ret = do_send(msg, cnx, hbh, peer), |
185 { | 185 { |
186 if (msg) { | 186 if (msg) { |
187 char buf[256]; | 187 char buf[256]; |
188 snprintf(buf, sizeof(buf), "Error while sending this message: %s", strerror(ret)); | 188 snprintf(buf, sizeof(buf), "Error while sending this message: %s", strerror(ret)); |
189 fd_hook_call(HOOK_MESSAGE_DROPPED, *msg, NULL, buf, fd_msg_pmdl_get(*msg)); | 189 fd_hook_call(HOOK_MESSAGE_DROPPED, *msg, NULL, buf, fd_msg_pmdl_get(*msg)); |
202 TRACE_ENTRY("%p", peer); | 202 TRACE_ENTRY("%p", peer); |
203 CHECK_PARAMS( CHECK_PEER(peer) && (peer->p_outthr == (pthread_t)NULL) ); | 203 CHECK_PARAMS( CHECK_PEER(peer) && (peer->p_outthr == (pthread_t)NULL) ); |
204 | 204 |
205 CHECK_POSIX( pthread_create(&peer->p_outthr, NULL, out_thr, peer) ); | 205 CHECK_POSIX( pthread_create(&peer->p_outthr, NULL, out_thr, peer) ); |
206 | 206 |
207 CHECK_FCT( fd_cnx_unordered_delivery(peer->p_cnxctx, 1) ); | |
208 | |
207 return 0; | 209 return 0; |
208 } | 210 } |
209 | 211 |
210 /* Stop that thread */ | 212 /* Stop that thread */ |
211 int fd_out_stop(struct fd_peer * peer) | 213 int fd_out_stop(struct fd_peer * peer) |
212 { | 214 { |
213 TRACE_ENTRY("%p", peer); | 215 TRACE_ENTRY("%p", peer); |
214 CHECK_PARAMS( CHECK_PEER(peer) ); | 216 CHECK_PARAMS( CHECK_PEER(peer) ); |
215 | 217 |
218 CHECK_FCT( fd_cnx_unordered_delivery(peer->p_cnxctx, 0) ); | |
219 | |
216 CHECK_FCT( fd_thr_term(&peer->p_outthr) ); | 220 CHECK_FCT( fd_thr_term(&peer->p_outthr) ); |
217 | 221 |
218 return 0; | 222 return 0; |
219 } | 223 } |
220 | 224 |