void rpcbuf::finish_request() { int length = pptr() - rptr(); if (rptr() && length > 0) { pbump(-length); mystream().width(FIELDWIDTH); mystream() << length; if (_actualWidth != pptr() - rptr()) { error("rpcbuf::finish_request: length field's width changed"); } pbump(length - (pptr() - rptr())); } setr(nil); }
int rpcbuf::overflow(int c) { if (!_opened || allocate() == EOF) { return EOF; } if (c == EOF) { finish_request(); } if (rptr() == pbase() && pptr() >= epptr() && !expand_p()) { error("rpcbuf::overflow: out of memory"); return EOF; } int nwrite = (rptr() >= pbase()) ? rptr() - pbase() : out_waiting(); int count = 0; while (count < nwrite) { int nsent = write(_fd, pbase() + count, nwrite - count); if (nsent < 0) { sys_error("rpcbuf::overflow: write"); return EOF; } count += nsent; } if (rptr() > pbase()) { Memory::copy(rptr(), pbase(), pptr() - rptr()); rbump(-nwrite); } pbump(-nwrite); if (c != EOF) { sputc(c); } return zapeof(c); }
int rpcbuf::start_request() { if (!_mystream || !_opened || allocate() == EOF) { return EOF; } finish_request(); setr(pptr()); const int length = 0; mystream().width(FIELDWIDTH); mystream() << length; _actualWidth = pptr() - rptr(); return 0; }
int MessageBlock::resize(size_t nsize) { try { DataBlock* ndb = new DataBlock(nsize); memcpy(ndb->addr(), rptr(), std::min(nsize, size())); wptr_ = size(); rptr_ = 0; dblock_->dec_ref(); dblock_ = ndb; } catch (std::exception& ex) { SYSLOG_ERROR("MessageBlock resize from %ld to %ld failed: %s", (long)size(), (long)nsize, ex.what()); return -1; } return 0; }