I have this simple code at dummy server side code:
---echo_read function
if (nread == 0) {
//I just want to have forcibly close client connection but the client
hangs
uv_close((uv_handle_t*) client, [](uv_handle_t* handle){
MybufferIo *io=static_cast<MybufferIo*>(handle->data);
free(handle);
delete io;
});
--- on new connection client
uv_tcp_init(loop, client);
if (uv_accept(server, (uv_stream_t*) client) == 0) {
// whether uv_tcp_queue_read *will always* emitting echo_read
function even if client send empty bytes?
uv_read_start((uv_stream_t*) client, alloc_buffer, echo_read);
}
My client code is like this one:
void onwrite(uv_write_t *req, int status) {
DataStatus *ds = static_cast<DataStatus *>(req->data);
free(req);
if (status < 0) {
free(ds->client);
uv_stop(ds->mainloop);
uv_loop_close (ds->mainloop);
return;
}
//I get 0 status whenever sending 0 bytes. but why the server code does
not really emit echo_read function?
//the source of problem client hangs is here. But I'm not really sure how
to handle this situation
uv_read_start((uv_stream_t*)ds->client, alloc_buffer, onread);
}
void on_connect(uv_connect_t *req, int status) {
DataStatus *ds = static_cast<DataStatus *>(req->data);
if (status < 0) {
ds->ok = false;
free(ds->client);
uv_stop(ds->mainloop);
uv_loop_close (ds->mainloop);
qDebug()<<"connect failed!";
return;
}
free(ds->write);
uv_write_t *wr=(uv_write_t*)malloc(sizeof(uv_write_t));
wr->data = (void *)ds;
ds->write=wr;
uv_stream_t *tcp =(uv_stream_t*) ds->client;
//original code is like this one.
//uv_buf_t buf = uv_buf_init(ds->tosend.data(), ds->tosend.size());
//but I want to change above code to something like this
uv_buf_t buf = uv_buf_init(( char*)"",0);
uv_write(wr, tcp, (const uv_buf_t *)&buf, 1, onwrite);
}
I have several questions:
1.whether uv_tcp_queue_read *will always* emitting echo_read function even
if client send empty bytes? I do see
based on above case is not even after successful calling of uv_accept at
server code?
2.the onwrite function at client side is called with 0 status and the
client just hangs,
but I've no clue to handle, probably the server side
code at libuv uv_tcp_queue_read *will always* not responding 0 bytes packet
data from client side. How to truly handle
this case?
thanks
--
You received this message because you are subscribed to the Google Groups
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.