Start sending immediately instead of waiting for another loop
parent
9d96e4bf0b
commit
79839ec31d
1
osd.h
1
osd.h
|
@ -219,6 +219,7 @@ class osd_t
|
|||
void handle_read(ring_data_t *data, int peer_fd);
|
||||
void handle_op_hdr(osd_client_t *cl);
|
||||
void handle_reply_hdr(osd_client_t *cl);
|
||||
bool try_send(osd_client_t & cl);
|
||||
void send_replies();
|
||||
void handle_send(ring_data_t *data, int peer_fd);
|
||||
void outbox_push(osd_client_t & cl, osd_op_t *op);
|
||||
|
|
28
osd_send.cpp
28
osd_send.cpp
|
@ -7,26 +7,25 @@ void osd_t::outbox_push(osd_client_t & cl, osd_op_t *cur_op)
|
|||
{
|
||||
gettimeofday(&cur_op->tv_begin, NULL);
|
||||
}
|
||||
cl.outbox.push_back(cur_op);
|
||||
if (cl.write_op || cl.outbox.size() > 1 || !try_send(cl))
|
||||
{
|
||||
if (cl.write_state == 0)
|
||||
{
|
||||
cl.write_state = CL_WRITE_READY;
|
||||
write_ready_clients.push_back(cur_op->peer_fd);
|
||||
}
|
||||
cl.outbox.push_back(cur_op);
|
||||
ringloop->wakeup();
|
||||
}
|
||||
}
|
||||
|
||||
void osd_t::send_replies()
|
||||
bool osd_t::try_send(osd_client_t & cl)
|
||||
{
|
||||
for (int i = 0; i < write_ready_clients.size(); i++)
|
||||
{
|
||||
int peer_fd = write_ready_clients[i];
|
||||
auto & cl = clients[peer_fd];
|
||||
int peer_fd = cl.peer_fd;
|
||||
io_uring_sqe* sqe = ringloop->get_sqe();
|
||||
if (!sqe)
|
||||
{
|
||||
write_ready_clients.erase(write_ready_clients.begin(), write_ready_clients.begin() + i);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
ring_data_t* data = ((ring_data_t*)sqe->user_data);
|
||||
if (!cl.write_op)
|
||||
|
@ -55,6 +54,19 @@ void osd_t::send_replies()
|
|||
cl.write_msg.msg_iovlen = cl.write_op->send_list.get_size();
|
||||
data->callback = [this, peer_fd](ring_data_t *data) { handle_send(data, peer_fd); };
|
||||
my_uring_prep_sendmsg(sqe, peer_fd, &cl.write_msg, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void osd_t::send_replies()
|
||||
{
|
||||
for (int i = 0; i < write_ready_clients.size(); i++)
|
||||
{
|
||||
int peer_fd = write_ready_clients[i];
|
||||
if (!try_send(clients[peer_fd]))
|
||||
{
|
||||
write_ready_clients.erase(write_ready_clients.begin(), write_ready_clients.begin() + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
write_ready_clients.clear();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue