Mercurial > hg > freeDiameter
comparison libfdcore/p_out.c @ 688:8c3dc8584dab
Prepared capability for messages logging to separate files / folders
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Wed, 19 Jan 2011 19:05:30 +0900 |
parents | 2e94ef0515d7 |
children | 78b665400097 |
comparison
equal
deleted
inserted
replaced
687:026802543f57 | 688:8c3dc8584dab |
---|---|
57 bkp_hbh = hdr->msg_hbhid; | 57 bkp_hbh = hdr->msg_hbhid; |
58 hdr->msg_hbhid = *hbh; | 58 hdr->msg_hbhid = *hbh; |
59 *hbh = hdr->msg_hbhid + 1; | 59 *hbh = hdr->msg_hbhid + 1; |
60 } | 60 } |
61 | 61 |
62 /* Log the message */ | |
63 if (TRACE_BOOL(FULL)) { | |
64 CHECK_FCT_DO( fd_msg_update_length(*msg), /* continue */ ); | |
65 TRACE_DEBUG(FULL, "Sending the following message on connection '%s':", fd_cnx_getid(cnx)); | |
66 fd_msg_dump_walk(FULL, *msg); | |
67 } | |
68 | |
69 /* Create the message buffer */ | 62 /* Create the message buffer */ |
70 CHECK_FCT(fd_msg_bufferize( *msg, &buf, &sz )); | 63 CHECK_FCT(fd_msg_bufferize( *msg, &buf, &sz )); |
71 pthread_cleanup_push( free, buf ); | 64 pthread_cleanup_push( free, buf ); |
65 | |
66 /* Log the message */ | |
67 fd_msg_log( FD_MSG_LOG_SENT, *msg, "Sent to '%s'", fd_cnx_getid(cnx)); | |
72 | 68 |
73 /* 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 */ |
74 if (msg_is_a_req) { | 70 if (msg_is_a_req) { |
75 CHECK_FCT_DO( ret = fd_p_sr_store(srl, msg, &hdr->msg_hbhid, bkp_hbh), { free(buf); return ret; } ); | 71 CHECK_FCT_DO( ret = fd_p_sr_store(srl, msg, &hdr->msg_hbhid, bkp_hbh), { free(buf); return ret; } ); |
76 } | 72 } |
90 | 86 |
91 static void cleanup_requeue(void * arg) | 87 static void cleanup_requeue(void * arg) |
92 { | 88 { |
93 struct msg *msg = arg; | 89 struct msg *msg = arg; |
94 CHECK_FCT_DO(fd_fifo_post(fd_g_outgoing, &msg), | 90 CHECK_FCT_DO(fd_fifo_post(fd_g_outgoing, &msg), |
95 CHECK_FCT_DO(fd_msg_free(msg), /* What can we do more? */)); | 91 { |
92 fd_msg_log( FD_MSG_LOG_DROPPED, msg, "An error occurred while attempting to requeue this message during cancellation of the sending function"); | |
93 CHECK_FCT_DO(fd_msg_free(msg), /* What can we do more? */); | |
94 } ); | |
96 } | 95 } |
97 | 96 |
98 /* The code of the "out" thread */ | 97 /* The code of the "out" thread */ |
99 static void * out_thr(void * arg) | 98 static void * out_thr(void * arg) |
100 { | 99 { |
109 } | 108 } |
110 | 109 |
111 /* Loop until cancelation */ | 110 /* Loop until cancelation */ |
112 while (1) { | 111 while (1) { |
113 struct msg * msg; | 112 struct msg * msg; |
113 int ret; | |
114 | 114 |
115 /* Retrieve next message to send */ | 115 /* Retrieve next message to send */ |
116 CHECK_FCT_DO( fd_fifo_get(peer->p_tosend, &msg), goto error ); | 116 CHECK_FCT_DO( fd_fifo_get(peer->p_tosend, &msg), goto error ); |
117 | 117 |
118 /* Now if we are cancelled, we requeue this message */ | 118 /* Now if we are cancelled, we requeue this message */ |
119 pthread_cleanup_push(cleanup_requeue, msg); | 119 pthread_cleanup_push(cleanup_requeue, msg); |
120 | 120 |
121 /* Send the message, log any error */ | 121 /* Send the message, log any error */ |
122 CHECK_FCT_DO( do_send(&msg, 0, peer->p_cnxctx, &peer->p_hbh, &peer->p_sr), | 122 CHECK_FCT_DO( ret = do_send(&msg, 0, peer->p_cnxctx, &peer->p_hbh, &peer->p_sr), |
123 { | 123 { |
124 if (msg) { | 124 if (msg) { |
125 fd_log_debug("An error occurred while sending this message, it was lost:\n"); | 125 fd_msg_log( FD_MSG_LOG_DROPPED, msg, "Internal error: Problem while sending (%s)\n", strerror(ret) ); |
126 fd_msg_dump_walk(NONE, msg); | |
127 fd_msg_free(msg); | 126 fd_msg_free(msg); |
128 } | 127 } |
129 } ); | 128 } ); |
130 | 129 |
131 /* Loop */ | 130 /* Loop */ |
148 if (peer && (peer->p_hdr.info.runtime.pir_state == STATE_OPEN)) { | 147 if (peer && (peer->p_hdr.info.runtime.pir_state == STATE_OPEN)) { |
149 /* Normal case: just queue for the out thread to pick it up */ | 148 /* Normal case: just queue for the out thread to pick it up */ |
150 CHECK_FCT( fd_fifo_post(peer->p_tosend, msg) ); | 149 CHECK_FCT( fd_fifo_post(peer->p_tosend, msg) ); |
151 | 150 |
152 } else { | 151 } else { |
152 int ret; | |
153 uint32_t *hbh = NULL; | 153 uint32_t *hbh = NULL; |
154 | 154 |
155 /* In other cases, the thread is not running, so we handle the sending directly */ | 155 /* In other cases, the thread is not running, so we handle the sending directly */ |
156 if (peer) | 156 if (peer) |
157 hbh = &peer->p_hbh; | 157 hbh = &peer->p_hbh; |
158 | 158 |
159 if (!cnx) | 159 if (!cnx) |
160 cnx = peer->p_cnxctx; | 160 cnx = peer->p_cnxctx; |
161 | 161 |
162 /* Do send the message */ | 162 /* Do send the message */ |
163 CHECK_FCT_DO( do_send(msg, flags, cnx, hbh, peer ? &peer->p_sr : NULL), | 163 CHECK_FCT_DO( ret = do_send(msg, flags, cnx, hbh, peer ? &peer->p_sr : NULL), |
164 { | 164 { |
165 if (msg) { | 165 if (msg) { |
166 fd_log_debug("An error occurred while sending this message, it was lost:\n"); | 166 fd_msg_log( FD_MSG_LOG_DROPPED, *msg, "Internal error: Problem while sending (%s)\n", strerror(ret) ); |
167 fd_msg_dump_walk(NONE, *msg); | |
168 fd_msg_free(*msg); | 167 fd_msg_free(*msg); |
169 *msg = NULL; | 168 *msg = NULL; |
170 } | 169 } |
171 } ); | 170 } ); |
172 } | 171 } |