write_handler.reset(new C_handle_write(this));
reset_handler.reset(new C_handle_reset(async_msgr, this));
remote_reset_handler.reset(new C_handle_remote_reset(async_msgr, this));
+ memset(msgvec, 0, sizeof(msgvec));
}
AsyncConnection::~AsyncConnection()
// else return < 0 means error
int AsyncConnection::_try_send(bufferlist send_bl, bool send)
{
- if (send_bl.length())
- outcoming_bl.claim_append(send_bl);
+ if (send_bl.length()) {
+ if (outcoming_bl.length())
+ outcoming_bl.claim_append(send_bl);
+ else
+ outcoming_bl.swap(send_bl);
+ }
if (!send)
return 0;
list<bufferptr>::const_iterator pb = outcoming_bl.buffers().begin();
while (outcoming_bl.length() > sended) {
struct msghdr msg;
- int size = MIN(outcoming_bl.buffers().size(), IOV_MAX);
- struct iovec *msgvec = new iovec[size];
+ int size = MIN(outcoming_bl.buffers().size(), IOV_LEN);
memset(&msg, 0, sizeof(msg));
msg.msg_iovlen = 0;
msg.msg_iov = msgvec;
if (r < 0)
return r;
- delete msgvec;
// "r" is the remaining length
sended += msglen - r;
if (r > 0) {
class AsyncMessenger;
class AsyncConnection : public Connection {
- const static uint64_t send_threshold = 16 * 1024 * 1024;
+ const static uint64_t IOV_LEN = 1024;
int read_bulk(int fd, char *buf, int len);
int do_sendmsg(struct msghdr &msg, int len, bool more);
state = STATE_ACCEPTING_WAIT_CONNECT_MSG;
return 0;
}
- bool _can_prepare_send() {
- if (outcoming_bl.length() > send_threshold)
- return false;
- return true;
- }
bool is_queued() {
return !out_q.empty() || outcoming_bl.length();
}
EventCallbackRef reset_handler;
EventCallbackRef remote_reset_handler;
bool keepalive;
+ struct iovec msgvec[IOV_LEN];
// Tis section are temp variables used by state transition