comparison libfdcore/p_out.c @ 1010:357c2f892d24

Implement a new counter on pending answers to send back to a peer. Function fd_peer_get_load_pending updated to retrieve this counter as well. When a peer has answers pending, the connection is not immediately teared down upon DPR/DPA exchange, but a GRACE_TIMEOUT delay (default 1 sec) is granted.
author Sebastien Decugis <sdecugis@freediameter.net>
date Mon, 25 Mar 2013 16:39:32 +0100
parents 5c564966a754
children 0117a7746b21
comparison
equal deleted inserted replaced
1009:e22434c66126 1010:357c2f892d24
170 } 170 }
171 171
172 /* 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) */ 172 /* 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) */
173 int fd_out_send(struct msg ** msg, struct cnxctx * cnx, struct fd_peer * peer, uint32_t flags) 173 int fd_out_send(struct msg ** msg, struct cnxctx * cnx, struct fd_peer * peer, uint32_t flags)
174 { 174 {
175 struct msg_hdr * hdr;
176
175 TRACE_ENTRY("%p %p %p %x", msg, cnx, peer, flags); 177 TRACE_ENTRY("%p %p %p %x", msg, cnx, peer, flags);
176 CHECK_PARAMS( msg && *msg && (cnx || (peer && peer->p_cnxctx))); 178 CHECK_PARAMS( msg && *msg && (cnx || (peer && peer->p_cnxctx)));
179
180 if (peer) {
181 CHECK_FCT( fd_msg_hdr(*msg, &hdr) );
182 if (!(hdr->msg_flags & CMD_FLAG_REQUEST)) {
183 /* Update the count of pending answers to send */
184 CHECK_POSIX( pthread_mutex_lock(&peer->p_state_mtx) );
185 peer->p_reqin_count--;
186 CHECK_POSIX( pthread_mutex_unlock(&peer->p_state_mtx) );
187 }
188 }
177 189
178 if (fd_peer_getstate(peer) == STATE_OPEN) { 190 if (fd_peer_getstate(peer) == STATE_OPEN) {
179 /* Normal case: just queue for the out thread to pick it up */ 191 /* Normal case: just queue for the out thread to pick it up */
180 CHECK_FCT( fd_fifo_post(peer->p_tosend, msg) ); 192 CHECK_FCT( fd_fifo_post(peer->p_tosend, msg) );
181 193
"Welcome to our mercurial repository"