1
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2
// vim: ts=8 sw=2 smarttab
11
int tcp_read(int sd, char *buf, int len) {
16
pfd.events = POLLIN | POLLHUP | POLLRDHUP | POLLNVAL | POLLERR;
18
if (poll(&pfd, 1, -1) < 0)
21
if (!(pfd.revents & POLLIN))
25
* although we turn on the MSG_DONTWAIT flag, we don't expect
26
* receivng an EAGAIN, as we polled on the socket, so there
27
* should be data waiting for us.
29
int got = ::recv( sd, buf, len, MSG_DONTWAIT );
32
//generic_dout(0) << "tcp_read socket " << sd << " returned " << got
33
//<< " errno " << errno << " " << strerror_r(errno, buf, sizeof(buf)) << dendl;
38
//generic_dout(DBL) << "tcp_read got " << got << ", " << len << " left" << dendl;
43
int tcp_write(int sd, const char *buf, int len) {
48
pfd.events = POLLOUT | POLLHUP | POLLRDHUP | POLLNVAL | POLLERR;
50
if (poll(&pfd, 1, -1) < 0)
53
if (!(pfd.revents & POLLOUT))
56
//generic_dout(DBL) << "tcp_write writing " << len << dendl;
59
int did = ::send( sd, buf, len, MSG_NOSIGNAL );
61
//generic_dout(1) << "tcp_write error did = " << did << " errno " << errno << " " << strerror(errno) << dendl;
62
//generic_derr(1) << "tcp_write error did = " << did << " errno " << errno << " " << strerror(errno) << dendl;
67
//generic_dout(DBL) << "tcp_write did " << did << ", " << len << " left" << dendl;