-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 04/25/2014 08:25 AM, zhengfish wrote:
>
> Hi, libuver
>
> In my server program I need to get the real socket handle(fd) after
> I call uv_accept. Whether I can get it? and How to do it?
>
> Here is the code snippet from echo-server.c, after it call
> uv_accecpt. The uv_accept will return the uv_stream_t* type --
> stream. Here how can I get the socket fd from stream variable?
>
> ----------------------------------- code-snippet from
> libuv-0.10.25
> -----------------------------------------------------
>
> static void on_connection ( uv_stream_t* server, int status ) {
> uv_stream_t* stream; int r;
>
> if ( status != 0 ) { fprintf ( stderr, "Connect error %d\n",
> uv_last_error ( loop ).code ); } ASSERT ( status == 0 );
>
> switch ( serverType ) { case TCP: stream = malloc ( sizeof (
> uv_tcp_t ) ); ASSERT ( stream != NULL ); r = uv_tcp_init ( loop, (
> uv_tcp_t* ) stream ); ASSERT ( r == 0 ); break;
>
> case PIPE: stream = malloc ( sizeof ( uv_pipe_t ) ); ASSERT (
> stream != NULL ); r = uv_pipe_init ( loop, ( uv_pipe_t* ) stream, 0
> ); ASSERT ( r == 0 ); break;
>
> default: ASSERT ( 0 && "Bad serverType" ); abort(); }
>
> /* associate server with stream */ stream->data = server;
>
> r = uv_accept ( server, stream ); ASSERT ( r == 0 );
>
> /// for libuv-v0.10.25 /// Here how can I get the socket fd(handle)
> from `stream` returned by uv_accept()?
>
> r = uv_read_start ( stream, echo_alloc, after_read ); ASSERT ( r ==
> 0 ); }
>
That's a non-portable implementation detail. Here is how you can do it
today, but note that it might change without notice, you are on your
own if you do this.
int fd = stream->io_watcher.fd;
- --
Saúl Ibarra Corretgé
bettercallsaghul.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Icedove - http://www.enigmail.net/
iQIcBAEBAgAGBQJTWhKLAAoJEEEOVVOum8BZRvQP/04YK4tGxilQYy5Eom/DKUb0
s2QVVzur5du4mP7l332KmzFYJYES7LDKdzsG12eTztLCTqjGwapuoTRD7IY0ZBlL
9qofRBoxAjVAFO4NyQS3xBF69F1oZB63jLJXyGJe7OvnBTlEAYPnSZ5B4hflklTT
/ag//0Jw8+rXTJz7brzD+TgAgxiHIdOK/IULR9+bm6ci27Snei9sMaYr32o7fizD
LWCTjHbqWgZSMmTlE6+mK7+AivJUNt/tF/dHicBCiuhwSRjFDboORWAphxMBeFHH
3YQWiwBUGBxdnyAzLbComvuw9BlC+VSgmXfHgLRtW+EeVt6fVdu/G3nPg4Si+s37
ZKpangCE0VbgnhY9zr+yWtP1sUfavW7t4UngkN9xVzxD1hf9dFCaZiTw7lnto9rC
H7AyAb4YuQjLyhUQAPeJCU75sJZLPvG/J6dXCs/8STyMuq8gb2P1JBkz6vTNQA3Q
UCWYM5ZwjlXSu7sBPfWNg0xHium2s8n6VRs+zAl+tHf+OD6E6f9sIA/8etXdwmrB
1/L8hS+eTYRiFmfH+m8OLCkhyn/dsrc5ufXB++/VJ0VuKINSa6NKetnlnXAVu4Rs
H/wtKvy+FgFCfttf23dhsk8Rr/w+UG/huHEkkX4CUe5xjNHDWfb1cvw5m3TeuOFp
DwdQbtH/yLMVBlxLMdpx
=oVGB
-----END PGP SIGNATURE-----
--
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 http://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.