Mercurial > hg > freeDiameter
comparison libfdcore/p_out.c @ 1103:d8591b1c56cd
Implemented a few hooks
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Fri, 10 May 2013 18:48:57 +0800 |
parents | 6b7966ea27fb |
children | eb4ce68b6e5c |
comparison
equal
deleted
inserted
replaced
1102:1d7b3ebda27f | 1103:d8591b1c56cd |
---|---|
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 sr_list * srl) | 39 static int do_send(struct msg ** msg, uint32_t flags, 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 | 47 struct msg *cpy_for_logs_only; |
48 TRACE_ENTRY("%p %x %p %p %p", msg, flags, cnx, hbh, srl); | 48 |
49 TRACE_ENTRY("%p %x %p %p %p", msg, flags, cnx, hbh, peer); | |
49 | 50 |
50 /* Retrieve the message header */ | 51 /* Retrieve the message header */ |
51 CHECK_FCT( fd_msg_hdr(*msg, &hdr) ); | 52 CHECK_FCT( fd_msg_hdr(*msg, &hdr) ); |
52 | 53 |
53 msg_is_a_req = (hdr->msg_flags & CMD_FLAG_REQUEST); | 54 msg_is_a_req = (hdr->msg_flags & CMD_FLAG_REQUEST); |
54 if (msg_is_a_req) { | 55 if (msg_is_a_req) { |
55 CHECK_PARAMS(hbh && srl); | 56 CHECK_PARAMS(hbh && peer); |
56 /* Alloc the hop-by-hop id and increment the value for next message */ | 57 /* Alloc the hop-by-hop id and increment the value for next message */ |
57 bkp_hbh = hdr->msg_hbhid; | 58 bkp_hbh = hdr->msg_hbhid; |
58 hdr->msg_hbhid = *hbh; | 59 hdr->msg_hbhid = *hbh; |
59 *hbh = hdr->msg_hbhid + 1; | 60 *hbh = hdr->msg_hbhid + 1; |
60 } | 61 } |
61 | 62 |
62 /* Create the message buffer */ | 63 /* Create the message buffer */ |
63 CHECK_FCT(fd_msg_bufferize( *msg, &buf, &sz )); | 64 CHECK_FCT(fd_msg_bufferize( *msg, &buf, &sz )); |
64 pthread_cleanup_push( free, buf ); | 65 pthread_cleanup_push( free, buf ); |
65 | 66 |
66 // cpy_for_logs_only = *msg; | 67 cpy_for_logs_only = *msg; |
67 | 68 |
68 /* Save a request before sending so that there is no race condition with the answer */ | 69 /* Save a request before sending so that there is no race condition with the answer */ |
69 if (msg_is_a_req) { | 70 if (msg_is_a_req) { |
70 CHECK_FCT_DO( ret = fd_p_sr_store(srl, msg, &hdr->msg_hbhid, bkp_hbh), goto out ); | 71 CHECK_FCT_DO( ret = fd_p_sr_store(&peer->p_sr, msg, &hdr->msg_hbhid, bkp_hbh), goto out ); |
71 } | 72 } |
72 | 73 |
73 /* Log the message */ | 74 /* Log the message */ |
74 // fd_msg_log( FD_MSG_LOG_SENT, cpy_for_logs_only, "Sent to '%s'", fd_cnx_getid(cnx)); | 75 fd_hook_call(HOOK_MESSAGE_SENT, cpy_for_logs_only, peer, NULL, fd_msg_pmdl_get(cpy_for_logs_only)); |
75 | 76 |
76 /* Send the message */ | 77 /* Send the message */ |
77 CHECK_FCT_DO( ret = fd_cnx_send(cnx, buf, sz, flags), ); | 78 CHECK_FCT_DO( ret = fd_cnx_send(cnx, buf, sz, flags), ); |
78 out: | 79 out: |
79 ; | 80 ; |
124 | 125 |
125 /* Now if we are cancelled, we requeue this message */ | 126 /* Now if we are cancelled, we requeue this message */ |
126 pthread_cleanup_push(cleanup_requeue, msg); | 127 pthread_cleanup_push(cleanup_requeue, msg); |
127 | 128 |
128 /* Send the message, log any error */ | 129 /* Send the message, log any error */ |
129 CHECK_FCT_DO( ret = do_send(&msg, 0, peer->p_cnxctx, &peer->p_hbh, &peer->p_sr), | 130 CHECK_FCT_DO( ret = do_send(&msg, 0, peer->p_cnxctx, &peer->p_hbh, peer), |
130 { | 131 { |
131 if (msg) { | 132 if (msg) { |
132 //fd_msg_log( FD_MSG_LOG_DROPPED, msg, "Internal error: Problem while sending (%s)", strerror(ret) ); | 133 //fd_msg_log( FD_MSG_LOG_DROPPED, msg, "Internal error: Problem while sending (%s)", strerror(ret) ); |
133 fd_msg_free(msg); | 134 fd_msg_free(msg); |
134 } | 135 } |
176 | 177 |
177 if (!cnx) | 178 if (!cnx) |
178 cnx = peer->p_cnxctx; | 179 cnx = peer->p_cnxctx; |
179 | 180 |
180 /* Do send the message */ | 181 /* Do send the message */ |
181 CHECK_FCT_DO( ret = do_send(msg, flags, cnx, hbh, peer ? &peer->p_sr : NULL), | 182 CHECK_FCT_DO( ret = do_send(msg, flags, cnx, hbh, peer), |
182 { | 183 { |
183 if (msg) { | 184 if (msg) { |
184 //fd_msg_log( FD_MSG_LOG_DROPPED, *msg, "Internal error: Problem while sending (%s)", strerror(ret) ); | 185 //fd_msg_log( FD_MSG_LOG_DROPPED, *msg, "Internal error: Problem while sending (%s)", strerror(ret) ); |
185 fd_msg_free(*msg); | 186 fd_msg_free(*msg); |
186 *msg = NULL; | 187 *msg = NULL; |