void echo_client_wcb_send(EV_P_ ev_io *w, int tev) { int sent_nb; echo_client_t *c = aux_memberof(echo_client_t, wev_send, w); sent_nb = aux_unix_send(w->fd, c->to_send_beg, c->to_send_size); /* sent_nb = aux_unix_send(w->fd, OUTPUT, sizeof(OUTPUT) - 1); */ /* fprintf(stderr, "sent %d bytes (%d: %s)\n", sent_nb, errno, strerror(errno)); */ if (0 > sent_nb) { if (EAGAIN == errno) { return; } fprintf(stderr, "send error fd=%d (%d: %s)\n", w->fd, errno, strerror(errno)); echo_client_del(c); return; } c->to_send_beg += sent_nb; c->to_send_size -= sent_nb; if (c->to_send_size > 0) { return; } ev_io_stop(loop, &c->wev_send); }
int client_send(client_t *c) { int nb = aux_unix_send(c->wev_recv.fd, REQUEST, sizeof(REQUEST) - 1); c->ts = ev_now(loop); /* fprintf(stderr, "send fd=%d\n", c->wev_recv.fd); */ if (0 > nb) { fprintf(stderr, "send error fd=%d (%d: %s)\n", c->wev_recv.fd, errno, strerror(errno)); client_del(c); return -1; } return 0; }
static void ugh_subreq_wcb_send(EV_P_ ev_io *w, int tev) { int rc; ugh_subreq_t *r = aux_memberof(ugh_subreq_t, wev_send, w); /* errno = 0; */ rc = aux_unix_send(w->fd, r->b_send.data + r->b_send.rpos, r->b_send.wpos - r->b_send.rpos); log_debug("subreq send: %d: %.*s", rc, (int) (r->b_send.wpos - r->b_send.rpos), r->b_send.data + r->b_send.rpos); if (0 > rc) { log_warn("send error %.*s%s%.*s (%d: %s)", (int) r->u.uri.size, r->u.uri.data, r->u.args.size ? "?" : "", (int) r->u.args.size, r->u.args.data, errno, aux_strerror(errno)); ugh_subreq_del(r, UGH_UPSTREAM_FT_ERROR); return; } /* log_debug("send %d bytes", rc); */ if (0 == rc) { return; } if (UGH_TIMEOUT_ONCE == r->timeout_type) { ev_timer_again(loop, &r->wev_timeout); } r->b_send.rpos += rc; if (r->b_send.rpos == r->b_send.wpos) { ev_io_stop(loop, &r->wev_send); ev_io_start(loop, &r->wev_recv); return; } }
void echo_client_wcb_recv(EV_P_ ev_io *w, int tev) { int nb; echo_client_t *c = aux_memberof(echo_client_t, wev_recv, w); int rem_size = c->to_send + TO_SEND_SIZE - (c->to_send_beg + c->to_send_size); if (rem_size < 32) { /* fprintf(stderr, "rem_size=%d, c->to_send_size=%u, fd=%d\n", rem_size, (unsigned) c->to_send_size, w->fd); */ memcpy(c->to_send, c->to_send_beg, c->to_send_size); c->to_send_beg = c->to_send; rem_size = TO_SEND_SIZE - c->to_send_size; /* fprintf(stderr, "rem_size=%d\n", rem_size); */ } nb = aux_unix_recv(w->fd, c->to_send_beg + c->to_send_size, rem_size); /* fprintf(stderr, "recv %d bytes (%d: %s) %.*s\n", nb, errno, strerror(errno), nb, buf); */ if (0 > nb) { if (EAGAIN == errno) { ev_timer_again(loop, &c->wev_timeout); return; } fprintf(stderr, "recv error fd=%d (%d: %s)\n", w->fd, errno, strerror(errno)); echo_client_del(c); return; } if (0 == nb) { /* fprintf(stderr, "recv done fd=%d\n", w->fd); */ /* echo_client_del(c); */ return; } c->to_send_size += nb; int sent_nb; sent_nb = aux_unix_send(w->fd, c->to_send_beg, c->to_send_size); /* nb = aux_unix_send(w->fd, OUTPUT, sizeof(OUTPUT) - 1); */ /* fprintf(stderr, "sent %d bytes (%d: %s)\n", nb, errno, strerror(errno)); */ if (0 > sent_nb) { if (EAGAIN == errno) { ev_io_start(loop, &c->wev_send); return; } fprintf(stderr, "send error fd=%d (%d: %s)\n", w->fd, errno, strerror(errno)); echo_client_del(c); return; } c->to_send_beg += sent_nb; c->to_send_size -= sent_nb; if (c->to_send_size > 0) { ev_io_start(loop, &c->wev_send); return; } #if 0 nb = aux_unix_send(w->fd, buf, nb); /* fprintf(stderr, "sent %d bytes (%d: %s)\n", nb, errno, strerror(errno)); */ if (0 > nb) { fprintf(stderr, "send error fd=%d (%d: %s)\n", w->fd, errno, strerror(errno)); echo_client_del(c); return; } ev_timer_again(loop, &c->wev_timeout); #endif }