使用libuv進行客戶端開發,在Linux下測試沒有問題,當移植到win7下面就報錯了,錯誤信息如下:
具體代碼:
.......
void uv_write_cb(uv_write_t *req,int status)
{
if(status == -1)
{
cout<<"error on_write_end"<<endl;
return;
}
//cout<<"write_end!!!"<<endl;
req->handle->data = req->data;
uv_read_start(req->handle,alloc_buffer,uv_read_cb);
//req->handle->loop->stop_flag = 1;
}
......
void connect_server(uv_connect_t *req,int status)
{
......
char buffer[100];
uv_buf_t buf = uv_buf_init(buffer,sizeof(buffer));
buf.len = strlen(fileName)+1;
buf.base = fileName;
uv_stream_t* tcp = req->handle;
uv_write_t write_req;
write_req.data = req->data;
int buf_count = 1;
uv_write(&write_req,tcp,&buf,buf_count,client::uv_write_cb);
......
}
int _tmain(int argc, _TCHAR* argv[])
{
......
_loop = uv_default_loop();
uv_tcp_t socket;
uv_tcp_init(_loop,&socket);
uv_connect_t connect;
connect.data = (void*)this;
//struct sockaddr dest;
struct sockaddr_in dest;
uv_ip4_addr(_ipaddr.c_str(),_port,&dest);
//struct sockaddr addrInfo;
uv_tcp_connect(&connect,&socket,(const struct sockaddr*)&dest,connect_server);
uv_run(_loop,UV_RUN_DEFAULT);
return 0;
......
}
已經解決!
問題分析:
局部變量引起loop捕獲不到事件。
解決方法:
把和uv相關的修改為全局的變量就沒問題了。