pipe_lock.Unlock();
char tag = -1;
- int rc;
+ int rc = -1;
struct msghdr msg;
struct iovec msgvec[2];
int msglen;
// create socket?
sd = ::socket(peer_addr.get_family(), SOCK_STREAM, 0);
if (sd < 0) {
- lderr(msgr->cct) << "connect couldn't created socket " << cpp_strerror(errno) << dendl;
+ rc = -errno;
+ lderr(msgr->cct) << "connect couldn't created socket " << cpp_strerror(rc) << dendl;
goto fail;
}
ldout(msgr->cct,10) << "connecting to " << peer_addr << dendl;
rc = ::connect(sd, (sockaddr*)&peer_addr.addr, peer_addr.addr_size());
if (rc < 0) {
+ rc = -errno;
ldout(msgr->cct,2) << "connect error " << peer_addr
- << ", " << cpp_strerror(errno) << dendl;
+ << ", " << cpp_strerror(rc) << dendl;
goto fail;
}
// verify banner
// FIXME: this should be non-blocking, or in some other way verify the banner as we get it.
- if (tcp_read((char*)&banner, strlen(CEPH_BANNER)) < 0) {
- ldout(msgr->cct,2) << "connect couldn't read banner, " << cpp_strerror(errno) << dendl;
+ rc = tcp_read((char*)&banner, strlen(CEPH_BANNER));
+ if (rc < 0) {
+ ldout(msgr->cct,2) << "connect couldn't read banner, " << cpp_strerror(rc) << dendl;
goto fail;
}
if (memcmp(banner, CEPH_BANNER, strlen(CEPH_BANNER))) {
msg.msg_iov = msgvec;
msg.msg_iovlen = 1;
msglen = msgvec[0].iov_len;
- if (do_sendmsg(&msg, msglen)) {
- ldout(msgr->cct,2) << "connect couldn't write my banner, " << cpp_strerror(errno) << dendl;
+ rc = do_sendmsg(&msg, msglen);
+ if (rc < 0) {
+ ldout(msgr->cct,2) << "connect couldn't write my banner, " << cpp_strerror(rc) << dendl;
goto fail;
}
#endif
addrbl.push_back(std::move(p));
}
- if (tcp_read(addrbl.c_str(), addrbl.length()) < 0) {
- ldout(msgr->cct,2) << "connect couldn't read peer addrs, " << cpp_strerror(errno) << dendl;
+ rc = tcp_read(addrbl.c_str(), addrbl.length());
+ if (rc < 0) {
+ ldout(msgr->cct,2) << "connect couldn't read peer addrs, " << cpp_strerror(rc) << dendl;
goto fail;
}
{
msg.msg_iov = msgvec;
msg.msg_iovlen = 1;
msglen = msgvec[0].iov_len;
- if (do_sendmsg(&msg, msglen)) {
- ldout(msgr->cct,2) << "connect couldn't write my addr, " << cpp_strerror(errno) << dendl;
+ rc = do_sendmsg(&msg, msglen);
+ if (rc < 0) {
+ ldout(msgr->cct,2) << "connect couldn't write my addr, " << cpp_strerror(rc) << dendl;
goto fail;
}
ldout(msgr->cct,10) << "connect sent my addr " << msgr->my_inst.addr << dendl;
ldout(msgr->cct,10) << "connect sending gseq=" << gseq << " cseq=" << cseq
<< " proto=" << connect.protocol_version << dendl;
- if (do_sendmsg(&msg, msglen)) {
- ldout(msgr->cct,2) << "connect couldn't write gseq, cseq, " << cpp_strerror(errno) << dendl;
+ rc = do_sendmsg(&msg, msglen);
+ if (rc < 0) {
+ ldout(msgr->cct,2) << "connect couldn't write gseq, cseq, " << cpp_strerror(rc) << dendl;
goto fail;
}
ldout(msgr->cct,20) << "connect wrote (self +) cseq, waiting for reply" << dendl;
ceph_msg_connect_reply reply;
- if (tcp_read((char*)&reply, sizeof(reply)) < 0) {
- ldout(msgr->cct,2) << "connect read reply " << cpp_strerror(errno) << dendl;
+ rc = tcp_read((char*)&reply, sizeof(reply));
+ if (rc < 0) {
+ ldout(msgr->cct,2) << "connect read reply " << cpp_strerror(rc) << dendl;
goto fail;
}
if (reply.authorizer_len) {
ldout(msgr->cct,10) << "reply.authorizer_len=" << reply.authorizer_len << dendl;
bufferptr bp = buffer::create(reply.authorizer_len);
- if (tcp_read(bp.c_str(), reply.authorizer_len) < 0) {
- ldout(msgr->cct,10) << "connect couldn't read connect authorizer_reply" << dendl;
+ rc = tcp_read(bp.c_str(), reply.authorizer_len);
+ if (rc < 0) {
+ ldout(msgr->cct,10) << "connect couldn't read connect authorizer_reply" << cpp_strerror(rc) << dendl;
goto fail;
}
authorizer_reply.push_back(bp);
if (reply.tag == CEPH_MSGR_TAG_SEQ) {
ldout(msgr->cct,10) << "got CEPH_MSGR_TAG_SEQ, reading acked_seq and writing in_seq" << dendl;
uint64_t newly_acked_seq = 0;
- if (tcp_read((char*)&newly_acked_seq, sizeof(newly_acked_seq)) < 0) {
- ldout(msgr->cct,2) << "connect read error on newly_acked_seq" << dendl;
+ rc = tcp_read((char*)&newly_acked_seq, sizeof(newly_acked_seq));
+ if (rc < 0) {
+ ldout(msgr->cct,2) << "connect read error on newly_acked_seq" << cpp_strerror(rc) << dendl;
goto fail_locked;
}
ldout(msgr->cct,2) << " got newly_acked_seq " << newly_acked_seq
stop_locked:
delete authorizer;
- return -1;
+ return rc;
}
void Pipe::register_pipe()
#endif
if (r == 0)
ldout(msgr->cct,10) << "do_sendmsg hmm do_sendmsg got r==0!" << dendl;
- if (r < 0) {
- ldout(msgr->cct,1) << "do_sendmsg error " << cpp_strerror(errno) << dendl;
+ if (r < 0) {
+ r = -errno;
+ ldout(msgr->cct,1) << "do_sendmsg error " << cpp_strerror(r) << dendl;
restore_sigpipe();
- return -1;
+ return r;
}
if (state == STATE_CLOSED) {
ldout(msgr->cct,10) << "do_sendmsg oh look, state == CLOSED, giving up" << dendl;
- errno = EINTR;
restore_sigpipe();
- return -1; // close enough
+ return -EINTR; // close enough
}
len -= r;
int Pipe::tcp_read(char *buf, unsigned len)
{
if (sd < 0)
- return -1;
+ return -EINVAL;
while (len > 0) {
int Pipe::tcp_read_wait()
{
if (sd < 0)
- return -1;
+ return -EINVAL;
struct pollfd pfd;
short evmask;
pfd.fd = sd;
return 0;
if (poll(&pfd, 1, msgr->timeout) <= 0)
- return -1;
+ return -errno;
evmask = POLLERR | POLLHUP | POLLNVAL;
#if defined(__linux__)