diff --git a/mio/bin/execd.c b/mio/bin/execd.c index 08dc3c9..96328c3 100644 --- a/mio/bin/execd.c +++ b/mio/bin/execd.c @@ -130,31 +130,31 @@ static void tcp_sck_on_disconnect (mio_dev_sck_t* tcp) switch (MIO_DEV_SCK_GET_PROGRESS(tcp)) { case MIO_DEV_SCK_CONNECTING: - MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->hnd); break; case MIO_DEV_SCK_CONNECTING_SSL: - MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO SSL-CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO SSL-CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->hnd); break; case MIO_DEV_SCK_LISTENING: - MIO_INFO1 (tcp->mio, "SHUTTING DOWN THE SERVER SOCKET(%d)...\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "SHUTTING DOWN THE SERVER SOCKET(%d)...\n", (int)tcp->hnd); break; case MIO_DEV_SCK_CONNECTED: - MIO_INFO1 (tcp->mio, "OUTGOING CLIENT CONNECTION GOT TORN DOWN(%d).......\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "OUTGOING CLIENT CONNECTION GOT TORN DOWN(%d).......\n", (int)tcp->hnd); break; case MIO_DEV_SCK_ACCEPTING_SSL: - MIO_INFO1 (tcp->mio, "INCOMING SSL-ACCEPT GOT DISCONNECTED(%d) ....\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "INCOMING SSL-ACCEPT GOT DISCONNECTED(%d) ....\n", (int)tcp->hnd); break; case MIO_DEV_SCK_ACCEPTED: - MIO_INFO1 (tcp->mio, "INCOMING CLIENT BEING SERVED GOT DISCONNECTED(%d).......\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "INCOMING CLIENT BEING SERVED GOT DISCONNECTED(%d).......\n", (int)tcp->hnd); break; default: - MIO_INFO2 (tcp->mio, "SOCKET DEVICE DISCONNECTED (%d - %x)\n", (int)tcp->sck, (unsigned int)tcp->state); + MIO_INFO2 (tcp->mio, "SOCKET DEVICE DISCONNECTED (%d - %x)\n", (int)tcp->hnd, (unsigned int)tcp->state); break; } } @@ -168,11 +168,11 @@ static void tcp_sck_on_connect (mio_dev_sck_t* tcp) if (tcp->state & MIO_DEV_SCK_CONNECTED) { - MIO_INFO3 (tcp->mio, "DEVICE connected to a remote server... LOCAL %hs REMOTE %hs SCK: %d\n", buf1, buf2, tcp->sck); + MIO_INFO3 (tcp->mio, "DEVICE connected to a remote server... LOCAL %hs REMOTE %hs SCK: %d\n", buf1, buf2, tcp->hnd); } else if (tcp->state & MIO_DEV_SCK_ACCEPTED) { - MIO_INFO3 (tcp->mio, "DEVICE accepted client device... .LOCAL %hs REMOTE %hs SCK: %d\n", buf1, buf2, tcp->sck); + MIO_INFO3 (tcp->mio, "DEVICE accepted client device... .LOCAL %hs REMOTE %hs SCK: %d\n", buf1, buf2, tcp->hnd); } if (mio_dev_sck_write(tcp, "hello", 5, MIO_NULL, MIO_NULL) <= -1) @@ -188,7 +188,7 @@ static int tcp_sck_on_write (mio_dev_sck_t* tcp, mio_iolen_t wrlen, void* wrctx, if (wrlen <= -1) { - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SEDING TIMED OUT...........\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SEDING TIMED OUT...........\n", (int)tcp->hnd); mio_dev_sck_halt (tcp); } else @@ -196,11 +196,11 @@ static int tcp_sck_on_write (mio_dev_sck_t* tcp, mio_iolen_t wrlen, void* wrctx, ts = (tcp_server_t*)(tcp + 1); if (wrlen == 0) { - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> CLOSED WRITING END\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> CLOSED WRITING END\n", (int)tcp->hnd); } else { - MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SENT MESSAGE %d of length %ld\n", (int)tcp->sck, ts->tally, (long int)wrlen); + MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SENT MESSAGE %d of length %ld\n", (int)tcp->hnd, ts->tally, (long int)wrlen); } ts->tally++; @@ -210,7 +210,7 @@ static int tcp_sck_on_write (mio_dev_sck_t* tcp, mio_iolen_t wrlen, void* wrctx, MIO_INIT_NTIME (&tmout, 5, 0); //mio_dev_sck_read (tcp, 1); - MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> REQUESTING to READ with timeout of %ld.%08ld\n", (int)tcp->sck, (long int)tmout.sec, (long int)tmout.nsec); + MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> REQUESTING to READ with timeout of %ld.%08ld\n", (int)tcp->hnd, (long int)tmout.sec, (long int)tmout.nsec); mio_dev_sck_timedread (tcp, 1, &tmout); } return 0; @@ -222,19 +222,19 @@ static int tcp_sck_on_read (mio_dev_sck_t* tcp, const void* buf, mio_iolen_t len if (len <= -1) { - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: TIMED OUT...\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: TIMED OUT...\n", (int)tcp->hnd); mio_dev_sck_halt (tcp); return 0; } else if (len <= 0) { - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: EOF RECEIVED...\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: EOF RECEIVED...\n", (int)tcp->hnd); /* no outstanding request. but EOF */ mio_dev_sck_halt (tcp); return 0; } - MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) - received %d bytes\n", (int)tcp->sck, (int)len); + MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) - received %d bytes\n", (int)tcp->hnd, (int)len); { mio_ntime_t tmout; @@ -243,7 +243,7 @@ static int tcp_sck_on_read (mio_dev_sck_t* tcp, const void* buf, mio_iolen_t len static char xxx[1000000]; memset (xxx, a++ , MIO_SIZEOF(xxx)); - MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) >>> REQUESTING to write data of %d bytes\n", (int)tcp->sck, MIO_SIZEOF(xxx)); + MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) >>> REQUESTING to write data of %d bytes\n", (int)tcp->hnd, MIO_SIZEOF(xxx)); //return mio_dev_sck_write (tcp, "HELLO", 5, MIO_NULL); MIO_INIT_NTIME (&tmout, 5, 0); n = mio_dev_sck_timedwrite(tcp, xxx, MIO_SIZEOF(xxx), &tmout, MIO_NULL, MIO_NULL); @@ -251,11 +251,11 @@ static int tcp_sck_on_read (mio_dev_sck_t* tcp, const void* buf, mio_iolen_t len if (n <= -1) return -1; } - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO STOP READ\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO STOP READ\n", (int)tcp->hnd); mio_dev_sck_read (tcp, 0); #if 0 - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO CLOSE WRITING END\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO CLOSE WRITING END\n", (int)tcp->hnd); /* post the write finisher - close the writing end */ n = mio_dev_sck_write(tcp, MIO_NULL, 0, MIO_NULL, MIO_NULL); if (n <= -1) return -1; diff --git a/mio/bin/t01.c b/mio/bin/t01.c index 69e8e3b..188cf81 100644 --- a/mio/bin/t01.c +++ b/mio/bin/t01.c @@ -142,31 +142,31 @@ static void tcp_sck_on_disconnect (mio_dev_sck_t* tcp) switch (MIO_DEV_SCK_GET_PROGRESS(tcp)) { case MIO_DEV_SCK_CONNECTING: - MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->hnd); break; case MIO_DEV_SCK_CONNECTING_SSL: - MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO SSL-CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO SSL-CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->hnd); break; case MIO_DEV_SCK_LISTENING: - MIO_INFO1 (tcp->mio, "SHUTTING DOWN THE SERVER SOCKET(%d)...\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "SHUTTING DOWN THE SERVER SOCKET(%d)...\n", (int)tcp->hnd); break; case MIO_DEV_SCK_CONNECTED: - MIO_INFO1 (tcp->mio, "OUTGOING CLIENT CONNECTION GOT TORN DOWN(%d).......\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "OUTGOING CLIENT CONNECTION GOT TORN DOWN(%d).......\n", (int)tcp->hnd); break; case MIO_DEV_SCK_ACCEPTING_SSL: - MIO_INFO1 (tcp->mio, "INCOMING SSL-ACCEPT GOT DISCONNECTED(%d) ....\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "INCOMING SSL-ACCEPT GOT DISCONNECTED(%d) ....\n", (int)tcp->hnd); break; case MIO_DEV_SCK_ACCEPTED: - MIO_INFO1 (tcp->mio, "INCOMING CLIENT BEING SERVED GOT DISCONNECTED(%d).......\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "INCOMING CLIENT BEING SERVED GOT DISCONNECTED(%d).......\n", (int)tcp->hnd); break; default: - MIO_INFO2 (tcp->mio, "SOCKET DEVICE DISCONNECTED (%d - %x)\n", (int)tcp->sck, (unsigned int)tcp->state); + MIO_INFO2 (tcp->mio, "SOCKET DEVICE DISCONNECTED (%d - %x)\n", (int)tcp->hnd, (unsigned int)tcp->state); break; } } @@ -191,11 +191,11 @@ static void tcp_sck_on_connect (mio_dev_sck_t* tcp) if (tcp->state & MIO_DEV_SCK_CONNECTED) { - MIO_INFO3 (tcp->mio, "DEVICE connected to a remote server... LOCAL %hs REMOTE %hs SCK: %d\n", buf1, buf2, tcp->sck); + MIO_INFO3 (tcp->mio, "DEVICE connected to a remote server... LOCAL %hs REMOTE %hs SCK: %d\n", buf1, buf2, tcp->hnd); } else if (tcp->state & MIO_DEV_SCK_ACCEPTED) { - MIO_INFO3 (tcp->mio, "DEVICE accepted client device... .LOCAL %hs REMOTE %hs SCK: %d\n", buf1, buf2, tcp->sck); + MIO_INFO3 (tcp->mio, "DEVICE accepted client device... .LOCAL %hs REMOTE %hs SCK: %d\n", buf1, buf2, tcp->hnd); } for (i = 0; i < MIO_COUNTOF(k); i++) k[i] = 'A' + (i % 26); @@ -220,7 +220,7 @@ static int tcp_sck_on_write (mio_dev_sck_t* tcp, mio_iolen_t wrlen, void* wrctx, if (wrlen <= -1) { - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SEDING TIMED OUT...........\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SEDING TIMED OUT...........\n", (int)tcp->hnd); mio_dev_sck_halt (tcp); } else @@ -228,11 +228,11 @@ static int tcp_sck_on_write (mio_dev_sck_t* tcp, mio_iolen_t wrlen, void* wrctx, ts = (tcp_server_t*)(tcp + 1); if (wrlen == 0) { - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> CLOSED WRITING END\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> CLOSED WRITING END\n", (int)tcp->hnd); } else { - MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SENT MESSAGE %d of length %ld\n", (int)tcp->sck, ts->tally, (long int)wrlen); + MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SENT MESSAGE %d of length %ld\n", (int)tcp->hnd, ts->tally, (long int)wrlen); } ts->tally++; @@ -242,7 +242,7 @@ static int tcp_sck_on_write (mio_dev_sck_t* tcp, mio_iolen_t wrlen, void* wrctx, MIO_INIT_NTIME (&tmout, 5, 0); //mio_dev_sck_read (tcp, 1); - MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> REQUESTING to READ with timeout of %ld.%08ld\n", (int)tcp->sck, (long int)tmout.sec, (long int)tmout.nsec); + MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> REQUESTING to READ with timeout of %ld.%08ld\n", (int)tcp->hnd, (long int)tmout.sec, (long int)tmout.nsec); mio_dev_sck_timedread (tcp, 1, &tmout); } return 0; @@ -254,19 +254,19 @@ static int tcp_sck_on_read (mio_dev_sck_t* tcp, const void* buf, mio_iolen_t len if (len <= -1) { - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: TIMED OUT...\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: TIMED OUT...\n", (int)tcp->hnd); mio_dev_sck_halt (tcp); return 0; } else if (len <= 0) { - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: EOF RECEIVED...\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: EOF RECEIVED...\n", (int)tcp->hnd); /* no outstanding request. but EOF */ mio_dev_sck_halt (tcp); return 0; } - MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) - received %d bytes\n", (int)tcp->sck, (int)len); + MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) - received %d bytes\n", (int)tcp->hnd, (int)len); { mio_ntime_t tmout; @@ -275,7 +275,7 @@ static int tcp_sck_on_read (mio_dev_sck_t* tcp, const void* buf, mio_iolen_t len static char xxx[1000000]; memset (xxx, a++ , MIO_SIZEOF(xxx)); - MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) >>> REQUESTING to write data of %d bytes\n", (int)tcp->sck, MIO_SIZEOF(xxx)); + MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) >>> REQUESTING to write data of %d bytes\n", (int)tcp->hnd, MIO_SIZEOF(xxx)); //return mio_dev_sck_write (tcp, "HELLO", 5, MIO_NULL); MIO_INIT_NTIME (&tmout, 5, 0); n = mio_dev_sck_timedwrite(tcp, xxx, MIO_SIZEOF(xxx), &tmout, MIO_NULL, MIO_NULL); @@ -283,11 +283,11 @@ static int tcp_sck_on_read (mio_dev_sck_t* tcp, const void* buf, mio_iolen_t len if (n <= -1) return -1; } - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO STOP READ\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO STOP READ\n", (int)tcp->hnd); mio_dev_sck_read (tcp, 0); #if 0 - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO CLOSE WRITING END\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO CLOSE WRITING END\n", (int)tcp->hnd); /* post the write finisher - close the writing end */ n = mio_dev_sck_write(tcp, MIO_NULL, 0, MIO_NULL, MIO_NULL); if (n <= -1) return -1; @@ -382,12 +382,12 @@ static int arp_sck_on_write (mio_dev_sck_t* dev, mio_iolen_t wrlen, void* wrctx, static void arp_sck_on_connect (mio_dev_sck_t* dev) { -printf ("STARTING UP ARP SOCKET %d...\n", dev->sck); +printf ("STARTING UP ARP SOCKET %d...\n", dev->hnd); } static void arp_sck_on_disconnect (mio_dev_sck_t* dev) { -printf ("SHUTTING DOWN ARP SOCKET %d...\n", dev->sck); +printf ("SHUTTING DOWN ARP SOCKET %d...\n", dev->hnd); } static int setup_arp_tester (mio_t* mio) @@ -584,7 +584,7 @@ static void icmp_sck_on_disconnect (mio_dev_sck_t* dev) icmpxtn = (icmpxtn_t*)(dev + 1); -printf ("SHUTTING DOWN ICMP SOCKET %d...\n", dev->sck); +printf ("SHUTTING DOWN ICMP SOCKET %d...\n", dev->hnd); if (icmpxtn->tmout_jobidx != MIO_TMRIDX_INVALID) { diff --git a/mio/bin/t02.c b/mio/bin/t02.c index ed29507..036a53c 100644 --- a/mio/bin/t02.c +++ b/mio/bin/t02.c @@ -64,31 +64,31 @@ static void tcp_sck_on_disconnect (mio_dev_sck_t* tcp) switch (MIO_DEV_SCK_GET_PROGRESS(tcp)) { case MIO_DEV_SCK_CONNECTING: - MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->hnd); break; case MIO_DEV_SCK_CONNECTING_SSL: - MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO SSL-CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO SSL-CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->hnd); break; case MIO_DEV_SCK_LISTENING: - MIO_INFO1 (tcp->mio, "SHUTTING DOWN THE SERVER SOCKET(%d)...\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "SHUTTING DOWN THE SERVER SOCKET(%d)...\n", (int)tcp->hnd); break; case MIO_DEV_SCK_CONNECTED: - MIO_INFO1 (tcp->mio, "OUTGOING CLIENT CONNECTION GOT TORN DOWN(%d).......\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "OUTGOING CLIENT CONNECTION GOT TORN DOWN(%d).......\n", (int)tcp->hnd); break; case MIO_DEV_SCK_ACCEPTING_SSL: - MIO_INFO1 (tcp->mio, "INCOMING SSL-ACCEPT GOT DISCONNECTED(%d) ....\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "INCOMING SSL-ACCEPT GOT DISCONNECTED(%d) ....\n", (int)tcp->hnd); break; case MIO_DEV_SCK_ACCEPTED: - MIO_INFO1 (tcp->mio, "INCOMING CLIENT BEING SERVED GOT DISCONNECTED(%d).......\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "INCOMING CLIENT BEING SERVED GOT DISCONNECTED(%d).......\n", (int)tcp->hnd); break; default: - MIO_INFO2 (tcp->mio, "SOCKET DEVICE DISCONNECTED (%d - %x)\n", (int)tcp->sck, (unsigned int)tcp->state); + MIO_INFO2 (tcp->mio, "SOCKET DEVICE DISCONNECTED (%d - %x)\n", (int)tcp->hnd, (unsigned int)tcp->state); break; } } @@ -102,11 +102,11 @@ static void tcp_sck_on_connect (mio_dev_sck_t* tcp) if (tcp->state & MIO_DEV_SCK_CONNECTED) { - MIO_INFO3 (tcp->mio, "DEVICE connected to a remote server... LOCAL %hs REMOTE %hs SCK: %d\n", buf1, buf2, tcp->sck); + MIO_INFO3 (tcp->mio, "DEVICE connected to a remote server... LOCAL %hs REMOTE %hs SCK: %d\n", buf1, buf2, tcp->hnd); } else if (tcp->state & MIO_DEV_SCK_ACCEPTED) { - MIO_INFO3 (tcp->mio, "DEVICE accepted client device... .LOCAL %hs REMOTE %hs SCK: %d\n", buf1, buf2, tcp->sck); + MIO_INFO3 (tcp->mio, "DEVICE accepted client device... .LOCAL %hs REMOTE %hs SCK: %d\n", buf1, buf2, tcp->hnd); } if (mio_dev_sck_write(tcp, "hello", 5, MIO_NULL, MIO_NULL) <= -1) @@ -122,7 +122,7 @@ static int tcp_sck_on_write (mio_dev_sck_t* tcp, mio_iolen_t wrlen, void* wrctx, if (wrlen <= -1) { - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SEDING TIMED OUT...........\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SEDING TIMED OUT...........\n", (int)tcp->hnd); mio_dev_sck_halt (tcp); } else @@ -130,11 +130,11 @@ static int tcp_sck_on_write (mio_dev_sck_t* tcp, mio_iolen_t wrlen, void* wrctx, ts = (tcp_xtn_t*)(tcp + 1); if (wrlen == 0) { - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> CLOSED WRITING END\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> CLOSED WRITING END\n", (int)tcp->hnd); } else { - MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SENT MESSAGE %d of length %ld\n", (int)tcp->sck, ts->tally, (long int)wrlen); + MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SENT MESSAGE %d of length %ld\n", (int)tcp->hnd, ts->tally, (long int)wrlen); } ts->tally++; @@ -144,7 +144,7 @@ static int tcp_sck_on_write (mio_dev_sck_t* tcp, mio_iolen_t wrlen, void* wrctx, MIO_INIT_NTIME (&tmout, 5, 0); //mio_dev_sck_read (tcp, 1); - MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> REQUESTING to READ with timeout of %ld.%08ld\n", (int)tcp->sck, (long int)tmout.sec, (long int)tmout.nsec); + MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> REQUESTING to READ with timeout of %ld.%08ld\n", (int)tcp->hnd, (long int)tmout.sec, (long int)tmout.nsec); mio_dev_sck_timedread (tcp, 1, &tmout); } return 0; @@ -156,19 +156,19 @@ static int tcp_sck_on_read (mio_dev_sck_t* tcp, const void* buf, mio_iolen_t len if (len <= -1) { - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: TIMED OUT...\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: TIMED OUT...\n", (int)tcp->hnd); mio_dev_sck_halt (tcp); return 0; } else if (len <= 0) { - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: EOF RECEIVED...\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: EOF RECEIVED...\n", (int)tcp->hnd); /* no outstanding request. but EOF */ mio_dev_sck_halt (tcp); return 0; } - MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) - received %d bytes\n", (int)tcp->sck, (int)len); + MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) - received %d bytes\n", (int)tcp->hnd, (int)len); { mio_ntime_t tmout; @@ -177,7 +177,7 @@ static int tcp_sck_on_read (mio_dev_sck_t* tcp, const void* buf, mio_iolen_t len static char xxx[1000000]; memset (xxx, a++ , MIO_SIZEOF(xxx)); - MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) >>> REQUESTING to write data of %d bytes\n", (int)tcp->sck, MIO_SIZEOF(xxx)); + MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) >>> REQUESTING to write data of %d bytes\n", (int)tcp->hnd, MIO_SIZEOF(xxx)); //return mio_dev_sck_write (tcp, "HELLO", 5, MIO_NULL); MIO_INIT_NTIME (&tmout, 5, 0); n = mio_dev_sck_timedwrite(tcp, xxx, MIO_SIZEOF(xxx), &tmout, MIO_NULL, MIO_NULL); @@ -185,11 +185,11 @@ static int tcp_sck_on_read (mio_dev_sck_t* tcp, const void* buf, mio_iolen_t len if (n <= -1) return -1; } - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO STOP READ\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO STOP READ\n", (int)tcp->hnd); mio_dev_sck_read (tcp, 0); #if 0 - MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO CLOSE WRITING END\n", (int)tcp->sck); + MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO CLOSE WRITING END\n", (int)tcp->hnd); /* post the write finisher - close the writing end */ n = mio_dev_sck_write(tcp, MIO_NULL, 0, MIO_NULL, MIO_NULL); if (n <= -1) return -1; diff --git a/mio/lib/http-svr.c b/mio/lib/http-svr.c index 946828f..ea5e75b 100644 --- a/mio/lib/http-svr.c +++ b/mio/lib/http-svr.c @@ -13,9 +13,8 @@ typedef struct mio_svc_htts_cli_t mio_svc_htts_cli_t; struct mio_svc_htts_cli_t { - mio_svc_htts_cli_t* cli_prev; - mio_svc_htts_cli_t* cli_next; - + /* a listener socket sets htts and sck fields only */ + /* a client sockets uses all the fields in this struct */ mio_svc_htts_t* htts; mio_dev_sck_t* sck; @@ -26,6 +25,9 @@ struct mio_svc_htts_cli_t mio_becs_t* sbuf; /* temporary buffer for status line formatting */ mio_svc_htts_rsrc_t rsrc; /* list head for resource list */ + + mio_svc_htts_cli_t* cli_prev; + mio_svc_htts_cli_t* cli_next; }; struct mio_svc_htts_t @@ -58,6 +60,13 @@ struct mio_svc_httc_t (cli)->cli_next->cli_prev = (cli)->cli_prev; \ } while (0) +#define CLIL_UNLINK_CLI_CLEAN(cli) do { \ + (cli)->cli_prev->cli_next = (cli)->cli_next; \ + (cli)->cli_next->cli_prev = (cli)->cli_prev; \ + (cli)->cli_prev = (cli); \ + (cli)->cli_next = (cli); \ +} while (0) + #define CLIL_INIT(lh) ((lh)->cli_next = (lh)->cli_prev = lh) #define CLIL_FIRST_CLI(lh) ((lh)->cli_next) #define CLIL_LAST_CLI(lh) ((lh)->cli_prev) @@ -374,6 +383,7 @@ static int init_client (mio_svc_htts_cli_t* cli, mio_dev_sck_t* sck) /* the htts field must be filled with the same field in the listening socket upon accept() */ MIO_ASSERT (sck->mio, cli->htts != MIO_NULL); + MIO_ASSERT (sck->mio, cli->sck == cli->htts->lsck); /* the field should still point to the listner socket */ MIO_ASSERT (sck->mio, sck->mio == cli->htts->mio); cli->htrd = mio_htrd_open(sck->mio, MIO_SIZEOF(*htrdxtn)); @@ -389,6 +399,7 @@ static int init_client (mio_svc_htts_cli_t* cli, mio_dev_sck_t* sck) cli->sck = sck; CLIL_APPEND_CLI (&cli->htts->cli, cli); +MIO_DEBUG3 (sck->mio, "HTTS(%p) - initialized client %p socket %p\n", cli->htts, cli, sck); return 0; oops: @@ -407,6 +418,8 @@ oops: static void fini_client (mio_svc_htts_cli_t* cli) { + MIO_DEBUG3 (cli->sck->mio, "HTTS(%p) - finalizing client %p socket %p\n", cli->htts, cli, cli->sck); + while (!RSRCL_IS_EMPTY(&cli->rsrc)) mio_svc_htts_rsrc_kill (RSRCL_FIRST_RSRC(&cli->rsrc)); @@ -421,7 +434,14 @@ static void fini_client (mio_svc_htts_cli_t* cli) cli->htrd = MIO_NULL; } - CLIL_UNLINK_CLI (cli); + CLIL_UNLINK_CLI_CLEAN (cli); + + /* are these needed? not symmetrical if done here. + * these fields are copied from the listener socket upon accept. + * init_client() doesn't fill in these fields. let's comment out these lines + cli->sck = MIO_NULL; + cli->htts = MIO_NULL; + */ } /* ------------------------------------------------------------------------ */ @@ -461,13 +481,6 @@ static int client_on_write (mio_dev_sck_t* sck, mio_iolen_t wrlen, void* wrctx, return 0; } -static void client_on_disconnect (mio_dev_sck_t* sck) -{ - mio_svc_htts_cli_t* cli = mio_dev_sck_getxtn(sck); -MIO_DEBUG1 (sck->mio, "** HTTS - client disconnect %p\n", sck); - fini_client (cli); -} - /* ------------------------------------------------------------------------ */ static int listener_on_read (mio_dev_sck_t* sck, const void* buf, mio_iolen_t len, const mio_skad_t* srcaddr) @@ -487,23 +500,22 @@ static void listener_on_connect (mio_dev_sck_t* sck) if (sck->state & MIO_DEV_SCK_ACCEPTED) { /* accepted a new client */ - MIO_DEBUG3 (sck->mio, "** HTTS(%p) - accepted... %p %d \n", cli->htts, sck, sck->sck); + MIO_DEBUG3 (sck->mio, "HTTS(%p) - accepted... %p %d \n", cli->htts, sck, sck->hnd); /* the accepted socket inherits various event callbacks. switch some of them to avoid sharing */ sck->on_read = client_on_read; sck->on_write = client_on_write; - sck->on_disconnect = client_on_disconnect; if (init_client(cli, sck) <= -1) { - MIO_INFO2 (sck->mio, "UNABLE TO INITIALIZE NEW CLIENT %p %d\n", sck, (int)sck->sck); + MIO_INFO2 (sck->mio, "UNABLE TO INITIALIZE NEW CLIENT %p %d\n", sck, (int)sck->hnd); mio_dev_sck_halt (sck); } } else if (sck->state & MIO_DEV_SCK_CONNECTED) { /* this will never be triggered as the listing socket never call mio_dev_sck_connect() */ - MIO_DEBUG3 (sck->mio, "** HTTS(%p) - connected... %p %d \n", cli->htts, sck, sck->sck); + MIO_DEBUG3 (sck->mio, "** HTTS(%p) - connected... %p %d \n", cli->htts, sck, sck->hnd); } /* MIO_DEV_SCK_CONNECTED must not be seen here as this is only for the listener socket */ @@ -517,44 +529,59 @@ static void listener_on_disconnect (mio_dev_sck_t* sck) { case MIO_DEV_SCK_CONNECTING: /* only for connecting sockets */ - MIO_INFO1 (sck->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO CONNECT (%d) TO REMOTE SERVER\n", (int)sck->sck); + MIO_INFO1 (sck->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO CONNECT (%d) TO REMOTE SERVER\n", (int)sck->hnd); break; case MIO_DEV_SCK_CONNECTING_SSL: /* only for connecting sockets */ - MIO_INFO1 (sck->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO SSL-CONNECT (%d) TO REMOTE SERVER\n", (int)sck->sck); + MIO_INFO1 (sck->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO SSL-CONNECT (%d) TO REMOTE SERVER\n", (int)sck->hnd); break; case MIO_DEV_SCK_CONNECTED: /* only for connecting sockets */ - MIO_INFO1 (sck->mio, "OUTGOING CLIENT CONNECTION GOT TORN DOWN %p(%d).......\n", (int)sck->sck); + MIO_INFO1 (sck->mio, "OUTGOING CLIENT CONNECTION GOT TORN DOWN %p(%d).......\n", (int)sck->hnd); break; case MIO_DEV_SCK_LISTENING: - MIO_INFO2 (sck->mio, "LISTNER SOCKET %p(%d) - SHUTTUING DOWN\n", sck, (int)sck->sck); + MIO_INFO2 (sck->mio, "LISTNER SOCKET %p(%d) - SHUTTUING DOWN\n", sck, (int)sck->hnd); break; - case MIO_DEV_SCK_ACCEPTING_SSL: - MIO_INFO2 (sck->mio, "LISTENER INCOMING SSL-ACCEPT GOT DISCONNECTED %p(%d) ....\n", sck, (int)sck->sck); - break; + case MIO_DEV_SCK_ACCEPTING_SSL: /* special case. */ + /* this progress code indicates that the ssl-level accept failed. + * on_disconnected() with this code is called without corresponding on_connect(). + * the cli extension are is not initialized yet */ + MIO_ASSERT (sck->mio, sck != cli->sck); + MIO_ASSERT (sck->mio, cli->sck == cli->htts->lsck); /* the field is a copy of the extension are of the listener socket. so it should point to the listner socket */ + MIO_INFO2 (sck->mio, "LISTENER UNABLE TO SSL-ACCEPT CLIENT %p(%d) ....%p\n", sck, (int)sck->hnd); + return; case MIO_DEV_SCK_ACCEPTED: /* only for sockets accepted by the listeners. will never come here because * the disconnect call for such sockets have been changed in listener_on_connect() */ - MIO_INFO2 (sck->mio, "ACCEPTED SOCKET %p(%d) GOT DISCONNECTED.......\n", sck, (int)sck->sck); + MIO_INFO2 (sck->mio, "ACCEPTED CLIENT SOCKET %p(%d) GOT DISCONNECTED.......\n", sck, (int)sck->hnd); break; default: - MIO_INFO2 (sck->mio, "SOCKET %p(%d) DISCONNECTED AFTER ALL.......\n", sck, (int)sck->sck); + MIO_INFO2 (sck->mio, "SOCKET %p(%d) DISCONNECTED AFTER ALL.......\n", sck, (int)sck->hnd); break; } - /* the client sockets are finalized in clinet_on_disconnect(). - * for a listener socket, these fields must be NULL */ - MIO_ASSERT (sck->mio, cli->htrd == MIO_NULL); - MIO_ASSERT (sck->mio, cli->sbuf == MIO_NULL); + if (sck == cli->htts->lsck) + { + /* the listener socket has these fields set to NULL */ + MIO_ASSERT (sck->mio, cli->htrd == MIO_NULL); + MIO_ASSERT (sck->mio, cli->sbuf == MIO_NULL); - cli->htts->lsck = MIO_NULL; /* let the htts service forget about this listening socket */ + MIO_DEBUG2 (sck->mio, "HTTS(%p) - listener socket disconnect %p\n", cli->htts, sck); + cli->htts->lsck = MIO_NULL; /* let the htts service forget about this listening socket */ + } + else + { + /* client socket */ + MIO_DEBUG2 (sck->mio, "HTTS(%p) - client socket disconnect %p\n", cli->htts, sck); + MIO_ASSERT (sck->mio, cli->sck == sck); + fini_client (cli); + } } @@ -602,15 +629,19 @@ mio_svc_htts_t* mio_svc_htts_start (mio_t* mio, const mio_skad_t* bind_addr) if (!htts->lsck) goto oops; /* the name 'cli' for the listening socket is awkard. - * the listing socket will use the htts field for tracking only. + * the listing socket will use the htts and sck fields for tracking only. * each accepted client socket gets the extension size for this size as well. * most of other fields are used for client management */ cli = (mio_svc_htts_cli_t*)mio_dev_sck_getxtn(htts->lsck); cli->htts = htts; + cli->sck = htts->lsck; MIO_MEMSET (&info, 0, MIO_SIZEOF(info)); info.b.localaddr = *bind_addr; info.b.options = MIO_DEV_SCK_BIND_REUSEADDR | MIO_DEV_SCK_BIND_REUSEPORT; + info.b.options |= MIO_DEV_SCK_BIND_SSL; + info.b.ssl_certfile = "localhost.crt"; + info.b.ssl_keyfile = "localhost.key"; if (mio_dev_sck_bind(htts->lsck, &info.b) <= -1) goto oops; MIO_MEMSET (&info, 0, MIO_SIZEOF(info)); @@ -626,7 +657,7 @@ mio_svc_htts_t* mio_svc_htts_start (mio_t* mio, const mio_skad_t* bind_addr) MIO_SVCL_APPEND_SVC (&mio->actsvc, (mio_svc_t*)htts); CLIL_INIT (&htts->cli); - MIO_DEBUG3 (mio, "STARTED SVC(HTTS) LISTENER %p LISTENER SOCKET %p(%d)\n", htts, htts->lsck, (int)htts->lsck->sck); + MIO_DEBUG3 (mio, "STARTED SVC(HTTS) LISTENER %p LISTENER SOCKET %p(%d)\n", htts, htts->lsck, (int)htts->lsck->hnd); return htts; oops: @@ -642,7 +673,7 @@ void mio_svc_htts_stop (mio_svc_htts_t* htts) { mio_t* mio = htts->mio; - MIO_DEBUG3 (mio, "STOPPING SVC(HTTS) %p LISTENER SOCKET %p(%d)\n", htts, htts->lsck, (int)(htts->lsck? htts->lsck->sck: -1)); + MIO_DEBUG3 (mio, "STOPPING SVC(HTTS) %p LISTENER SOCKET %p(%d)\n", htts, htts->lsck, (int)(htts->lsck? htts->lsck->hnd: -1)); /* htts->lsck may be null if the socket has been destroyed for operational error and * forgotten in the disconnect callback thereafter */ @@ -704,7 +735,6 @@ void mio_svc_htts_rsrc_kill (mio_svc_htts_rsrc_t* rsrc) printf ("RSRC KILL >>>>> %p\n", rsrc->htts); mio_t* mio = rsrc->htts->mio; - if (rsrc->on_kill) rsrc->on_kill (rsrc); RSRCL_UNLINK_RSRC (rsrc); @@ -1033,7 +1063,7 @@ int mio_svc_htts_docgi (mio_svc_htts_t* htts, mio_dev_sck_t* csck, mio_htre_t* r #endif #if 0 - rsrc = mio_svc_htts_rsrc_make(htts, csck, rsrc_cgi_on_write, rsrc_cgi_on_kill, MIO_SIZEOF(*rsrc_cgi)); + rsrc = mio_svc_htts_rsrc_make(htts, csck, rsrc_cgi_on_read, rsrc_cgi_on_write, rsrc_cgi_on_kill, MIO_SIZEOF(*rsrc_cgi)); if (MIO_UNLIKELY(!rsrc)) goto oops; #endif diff --git a/mio/lib/mio-sck.h b/mio/lib/mio-sck.h index 17ca09c..3005ce3 100644 --- a/mio/lib/mio-sck.h +++ b/mio/lib/mio-sck.h @@ -363,7 +363,7 @@ struct mio_dev_sck_t MIO_DEV_HEADER; mio_dev_sck_type_t type; - mio_sckhnd_t sck; + mio_sckhnd_t hnd; int state; diff --git a/mio/lib/mio.c b/mio/lib/mio.c index 3746420..9e4fff1 100644 --- a/mio/lib/mio.c +++ b/mio/lib/mio.c @@ -703,6 +703,7 @@ mio_dev_t* mio_dev_make (mio_t* mio, mio_oow_t dev_size, mio_dev_mth_t* dev_mth, if (!(dev->dev_cap & MIO_DEV_CAP_OUT)) dev->dev_cap |= MIO_DEV_CAP_OUT_CLOSED; if (mio_dev_watch(dev, MIO_DEV_WATCH_START, 0) <= -1) goto oops_after_make; + /* and place the new device object at the back of the active device list */ MIO_DEVL_APPEND_DEV (&mio->actdev, dev); dev->dev_cap |= MIO_DEV_CAP_ACTIVE; diff --git a/mio/lib/sck.c b/mio/lib/sck.c index f2f749f..195849f 100644 --- a/mio/lib/sck.c +++ b/mio/lib/sck.c @@ -300,8 +300,8 @@ static int dev_sck_make (mio_dev_t* dev, void* ctx) return -1; } - rdev->sck = open_async_socket(mio, sck_type_map[arg->type].domain, sck_type_map[arg->type].type, sck_type_map[arg->type].proto); - if (rdev->sck == MIO_SCKHND_INVALID) goto oops; + rdev->hnd = open_async_socket(mio, sck_type_map[arg->type].domain, sck_type_map[arg->type].type, sck_type_map[arg->type].proto); + if (rdev->hnd == MIO_SCKHND_INVALID) goto oops; rdev->dev_cap = MIO_DEV_CAP_IN | MIO_DEV_CAP_OUT | sck_type_map[arg->type].extra_dev_cap; rdev->on_write = arg->on_write; @@ -314,10 +314,10 @@ static int dev_sck_make (mio_dev_t* dev, void* ctx) return 0; oops: - if (rdev->sck != MIO_SCKHND_INVALID) + if (rdev->hnd != MIO_SCKHND_INVALID) { - close_async_socket (mio, rdev->sck); - rdev->sck = MIO_SCKHND_INVALID; + close_async_socket (mio, rdev->hnd); + rdev->hnd = MIO_SCKHND_INVALID; } return -1; } @@ -334,14 +334,14 @@ static int dev_sck_make_client (mio_dev_t* dev, void* ctx) * most of the initialization is done by the listening socket device * after a client socket has been created. */ - rdev->sck = *sck; + rdev->hnd = *sck; rdev->tmrjob_index = MIO_TMRIDX_INVALID; - if (mio_makesckasync(mio, rdev->sck) <= -1) return -1; + if (mio_makesckasync(mio, rdev->hnd) <= -1) return -1; #if defined(FD_CLOEXEC) { - int flags = fcntl(rdev->sck, F_GETFD, 0); - if (fcntl(rdev->sck, F_SETFD, flags | FD_CLOEXEC) == -1) + int flags = fcntl(rdev->hnd, F_GETFD, 0); + if (fcntl(rdev->hnd, F_SETFD, flags | FD_CLOEXEC) == -1) { mio_seterrbfmtwithsyserr (mio, 0, errno, "unable to set FD_CLOEXEC"); return -1; @@ -361,8 +361,9 @@ static int dev_sck_kill (mio_dev_t* dev, int force) { /*if (MIO_DEV_SCK_GET_PROGRESS(rdev)) {*/ - /* for MIO_DEV_SCK_CONNECTING, MIO_DEV_SCK_CONNECTING_SSL, and MIO_DEV_ACCEPTING_SSL - * on_disconnect() is called without corresponding on_connect() */ + /* for MIO_DEV_SCK_CONNECTING, MIO_DEV_SCK_CONNECTING_SSL, and MIO_DEV_SCK_ACCEPTING_SSL + * on_disconnect() is called without corresponding on_connect(). + * it is the same if connect or accept has not been called. */ if (rdev->on_disconnect) rdev->on_disconnect (rdev); /*}*/ @@ -394,10 +395,10 @@ static int dev_sck_kill (mio_dev_t* dev, int force) } #endif - if (rdev->sck != MIO_SCKHND_INVALID) + if (rdev->hnd != MIO_SCKHND_INVALID) { - close_async_socket (mio, rdev->sck); - rdev->sck = MIO_SCKHND_INVALID; + close_async_socket (mio, rdev->hnd); + rdev->hnd = MIO_SCKHND_INVALID; } return 0; @@ -406,7 +407,7 @@ static int dev_sck_kill (mio_dev_t* dev, int force) static mio_syshnd_t dev_sck_getsyshnd (mio_dev_t* dev) { mio_dev_sck_t* rdev = (mio_dev_sck_t*)dev; - return (mio_syshnd_t)rdev->sck; + return (mio_syshnd_t)rdev->hnd; } static int dev_sck_read_stateful (mio_dev_t* dev, void* buf, mio_iolen_t* len, mio_devaddr_t* srcaddr) @@ -435,7 +436,7 @@ static int dev_sck_read_stateful (mio_dev_t* dev, void* buf, mio_iolen_t* len, m #endif ssize_t x; - x = recv(rdev->sck, buf, *len, 0); + x = recv(rdev->hnd, buf, *len, 0); if (x == -1) { if (errno == EINPROGRESS || errno == EWOULDBLOCK || errno == EAGAIN) return 0; /* no data available */ @@ -459,7 +460,7 @@ static int dev_sck_read_stateless (mio_dev_t* dev, void* buf, mio_iolen_t* len, ssize_t x; srcaddrlen = MIO_SIZEOF(rdev->remoteaddr); - x = recvfrom(rdev->sck, buf, *len, 0, (struct sockaddr*)&rdev->remoteaddr, &srcaddrlen); + x = recvfrom(rdev->hnd, buf, *len, 0, (struct sockaddr*)&rdev->remoteaddr, &srcaddrlen); if (x <= -1) { if (errno == EINPROGRESS || errno == EWOULDBLOCK || errno == EAGAIN) return 0; /* no data available */ @@ -520,7 +521,7 @@ static int dev_sck_write_stateful (mio_dev_t* dev, const void* data, mio_iolen_t /* the write handler for a stream device must handle a zero-length * writing request specially. it's a writing finish indicator. close * the writing end of the socket, probably leaving it in the half-closed state */ - if (shutdown(rdev->sck, SHUT_WR) == -1) + if (shutdown(rdev->hnd, SHUT_WR) == -1) { mio_seterrwithsyserr (mio, 0, errno); return -1; @@ -535,7 +536,7 @@ static int dev_sck_write_stateful (mio_dev_t* dev, const void* data, mio_iolen_t #if defined(MSG_NOSIGNAL) flags |= MSG_NOSIGNAL; #endif - x = send(rdev->sck, data, *len, flags); + x = send(rdev->hnd, data, *len, flags); if (x == -1) { if (errno == EINPROGRESS || errno == EWOULDBLOCK || errno == EAGAIN) return 0; /* no data can be written */ @@ -605,7 +606,7 @@ static int dev_sck_writev_stateful (mio_dev_t* dev, const mio_iovec_t* iov, mio_ { /* it's a writing finish indicator. close the writing end of * the socket, probably leaving it in the half-closed state */ - if (shutdown(rdev->sck, SHUT_WR) == -1) + if (shutdown(rdev->hnd, SHUT_WR) == -1) { mio_seterrwithsyserr (mio, 0, errno); return -1; @@ -623,9 +624,9 @@ static int dev_sck_writev_stateful (mio_dev_t* dev, const mio_iovec_t* iov, mio_ MIO_MEMSET (&msg, 0, MIO_SIZEOF(msg)); msg.msg_iov = (struct iovec*)iov; msg.msg_iovlen = *iovcnt; - x = sendmsg(rdev->sck, &msg, flags); + x = sendmsg(rdev->hnd, &msg, flags); #else - x = writev(rdev->sck, (const struct iovec*)iov, *iovcnt); + x = writev(rdev->hnd, (const struct iovec*)iov, *iovcnt); #endif if (x == -1) { @@ -648,7 +649,7 @@ static int dev_sck_write_stateless (mio_dev_t* dev, const void* data, mio_iolen_ mio_dev_sck_t* rdev = (mio_dev_sck_t*)dev; ssize_t x; - x = sendto(rdev->sck, data, *len, 0, dstaddr->ptr, dstaddr->len); + x = sendto(rdev->hnd, data, *len, 0, dstaddr->ptr, dstaddr->len); if (x <= -1) { if (errno == EINPROGRESS || errno == EWOULDBLOCK || errno == EAGAIN) return 0; /* no data can be written */ @@ -677,7 +678,7 @@ static int dev_sck_writev_stateless (mio_dev_t* dev, const mio_iovec_t* iov, mio msg.msg_iov = (struct iovec*)iov; msg.msg_iovlen = *iovcnt; - x = sendmsg(rdev->sck, &msg, 0); + x = sendmsg(rdev->hnd, &msg, 0); if (x <= -1) { if (errno == EINPROGRESS || errno == EWOULDBLOCK || errno == EAGAIN) return 0; /* no data can be written */ @@ -710,7 +711,7 @@ static int do_ssl (mio_dev_sck_t* dev, int (*ssl_func)(SSL*)) return -1; } - if (SSL_set_fd(ssl, dev->sck) == 0) + if (SSL_set_fd(ssl, dev->hnd) == 0) { set_ssl_error (mio, ERR_get_error()); return -1; @@ -722,7 +723,7 @@ static int do_ssl (mio_dev_sck_t* dev, int (*ssl_func)(SSL*)) } watcher_cmd = MIO_DEV_WATCH_RENEW; - watcher_events = 0; + watcher_events = MIO_DEV_EVENT_IN; ret = ssl_func((SSL*)dev->ssl); if (ret <= 0) @@ -762,12 +763,12 @@ static int do_ssl (mio_dev_sck_t* dev, int (*ssl_func)(SSL*)) static MIO_INLINE int connect_ssl (mio_dev_sck_t* dev) { - return do_ssl (dev, SSL_connect); + return do_ssl(dev, SSL_connect); } static MIO_INLINE int accept_ssl (mio_dev_sck_t* dev) { - return do_ssl (dev, SSL_accept); + return do_ssl(dev, SSL_accept); } #endif @@ -795,7 +796,7 @@ static int dev_sck_ioctl (mio_dev_t* dev, int cmd, void* arg) if (bnd->options & MIO_DEV_SCK_BIND_BROADCAST) { int v = 1; - if (setsockopt(rdev->sck, SOL_SOCKET, SO_BROADCAST, &v, MIO_SIZEOF(v)) == -1) + if (setsockopt(rdev->hnd, SOL_SOCKET, SO_BROADCAST, &v, MIO_SIZEOF(v)) == -1) { mio_seterrbfmtwithsyserr (mio, 0, errno, "unable to set SO_BROADCAST"); return -1; @@ -806,7 +807,7 @@ static int dev_sck_ioctl (mio_dev_t* dev, int cmd, void* arg) { #if defined(SO_REUSEADDR) int v = 1; - if (setsockopt(rdev->sck, SOL_SOCKET, SO_REUSEADDR, &v, MIO_SIZEOF(v)) == -1) + if (setsockopt(rdev->hnd, SOL_SOCKET, SO_REUSEADDR, &v, MIO_SIZEOF(v)) == -1) { mio_seterrbfmtwithsyserr (mio, 0, errno, "unable to set SO_REUSEADDR"); return -1; @@ -823,7 +824,7 @@ static int dev_sck_ioctl (mio_dev_t* dev, int cmd, void* arg) { #if defined(SO_REUSEPORT) int v = 1; - if (setsockopt(rdev->sck, SOL_SOCKET, SO_REUSEPORT, &v, MIO_SIZEOF(v)) == -1) + if (setsockopt(rdev->hnd, SOL_SOCKET, SO_REUSEPORT, &v, MIO_SIZEOF(v)) == -1) { mio_seterrbfmtwithsyserr (mio, 0, errno, "unable to set SO_REUSEPORT"); return -1; @@ -840,7 +841,7 @@ static int dev_sck_ioctl (mio_dev_t* dev, int cmd, void* arg) { #if defined(IP_TRANSPARENT) int v = 1; - if (setsockopt(rdev->sck, SOL_IP, IP_TRANSPARENT, &v, MIO_SIZEOF(v)) == -1) + if (setsockopt(rdev->hnd, SOL_IP, IP_TRANSPARENT, &v, MIO_SIZEOF(v)) == -1) { mio_seterrbfmtwithsyserr (mio, 0, errno, "unable to set IP_TRANSPARENT"); return -1; @@ -888,7 +889,7 @@ static int dev_sck_ioctl (mio_dev_t* dev, int cmd, void* arg) if (SSL_CTX_use_certificate_file(ssl_ctx, bnd->ssl_certfile, SSL_FILETYPE_PEM) == 0 || SSL_CTX_use_PrivateKey_file(ssl_ctx, bnd->ssl_keyfile, SSL_FILETYPE_PEM) == 0 || SSL_CTX_check_private_key(ssl_ctx) == 0 /*|| - SSL_CTX_use_certificate_chain_file (ssl_ctx, bnd->chainfile) == 0*/) + SSL_CTX_use_certificate_chain_file(ssl_ctx, bnd->chainfile) == 0*/) { set_ssl_error (mio, ERR_get_error()); SSL_CTX_free (ssl_ctx); @@ -907,7 +908,7 @@ static int dev_sck_ioctl (mio_dev_t* dev, int cmd, void* arg) #endif } - x = bind(rdev->sck, (struct sockaddr*)&bnd->localaddr, mio_skad_size(&bnd->localaddr)); + x = bind(rdev->hnd, (struct sockaddr*)&bnd->localaddr, mio_skad_size(&bnd->localaddr)); if (x == -1) { mio_seterrwithsyserr (mio, 0, errno); @@ -987,13 +988,13 @@ static int dev_sck_ioctl (mio_dev_t* dev, int cmd, void* arg) #endif /* the socket is already non-blocking */ /*{ -int flags = fcntl (rdev->sck, F_GETFL); -fcntl (rdev->sck, F_SETFL, flags & ~O_NONBLOCK); +int flags = fcntl (rdev->hnd, F_GETFL); +fcntl (rdev->hnd, F_SETFL, flags & ~O_NONBLOCK); }*/ - x = connect(rdev->sck, sa, sl); + x = connect(rdev->hnd, sa, sl); /*{ -int flags = fcntl (rdev->sck, F_GETFL); -fcntl (rdev->sck, F_SETFL, flags | O_NONBLOCK); +int flags = fcntl (rdev->hnd, F_GETFL); +fcntl (rdev->hnd, F_SETFL, flags | O_NONBLOCK); }*/ if (x <= -1) { @@ -1089,7 +1090,7 @@ fcntl (rdev->sck, F_SETFL, flags | O_NONBLOCK); return -1; } - x = listen(rdev->sck, lstn->backlogs); + x = listen(rdev->hnd, lstn->backlogs); if (x == -1) { mio_seterrwithsyserr (mio, 0, errno); @@ -1154,7 +1155,7 @@ static int harvest_outgoing_connection (mio_dev_sck_t* rdev) MIO_ASSERT (mio, !(rdev->state & MIO_DEV_SCK_CONNECTED)); len = MIO_SIZEOF(errcode); - if (getsockopt(rdev->sck, SOL_SOCKET, SO_ERROR, (char*)&errcode, &len) == -1) + if (getsockopt(rdev->hnd, SOL_SOCKET, SO_ERROR, (char*)&errcode, &len) == -1) { mio_seterrbfmtwithsyserr (mio, 0, errno, "unable to get SO_ERROR"); return -1; @@ -1173,7 +1174,7 @@ static int harvest_outgoing_connection (mio_dev_sck_t* rdev) } addrlen = MIO_SIZEOF(localaddr); - if (getsockname(rdev->sck, (struct sockaddr*)&localaddr, &addrlen) == 0) rdev->localaddr = localaddr; + if (getsockname(rdev->hnd, (struct sockaddr*)&localaddr, &addrlen) == 0) rdev->localaddr = localaddr; if (mio_dev_watch((mio_dev_t*)rdev, MIO_DEV_WATCH_RENEW, MIO_DEV_EVENT_IN) <= -1) { @@ -1252,7 +1253,7 @@ static int accept_incoming_connection (mio_dev_sck_t* rdev) flags = SOCK_NONBLOCK | SOCK_CLOEXEC; addrlen = MIO_SIZEOF(remoteaddr); - clisck = accept4(rdev->sck, (struct sockaddr*)&remoteaddr, &addrlen, flags); + clisck = accept4(rdev->hnd, (struct sockaddr*)&remoteaddr, &addrlen, flags); if (clisck == MIO_SCKHND_INVALID) { if (errno != ENOSYS) @@ -1273,7 +1274,7 @@ static int accept_incoming_connection (mio_dev_sck_t* rdev) #endif addrlen = MIO_SIZEOF(remoteaddr); - clisck = accept(rdev->sck, (struct sockaddr*)&remoteaddr, &addrlen); + clisck = accept(rdev->hnd, (struct sockaddr*)&remoteaddr, &addrlen); if (clisck == MIO_SCKHND_INVALID) { if (errno == EINPROGRESS || errno == EWOULDBLOCK || errno == EAGAIN) return 0; @@ -1295,7 +1296,7 @@ accept_done: return -1; } - MIO_ASSERT (mio, clidev->sck == clisck); + MIO_ASSERT (mio, clidev->hnd == clisck); clidev->dev_cap |= MIO_DEV_CAP_IN | MIO_DEV_CAP_OUT | MIO_DEV_CAP_STREAM; clidev->remoteaddr = remoteaddr; @@ -1365,7 +1366,6 @@ accept_done: if (MIO_IS_POS_NTIME(&rdev->tmout) && schedule_timer_job_after(clidev, &rdev->tmout, ssl_accept_timedout) <= -1) { - /* TODO: call a warning/error callback */ /* timer job scheduling failed. halt the device */ mio_dev_halt ((mio_dev_t*)clidev); } @@ -1391,7 +1391,7 @@ static int dev_evcb_sck_ready_stateful (mio_dev_t* dev, int events) mio_scklen_t len; len = MIO_SIZEOF(errcode); - if (getsockopt(rdev->sck, SOL_SOCKET, SO_ERROR, (char*)&errcode, &len) == -1) + if (getsockopt(rdev->hnd, SOL_SOCKET, SO_ERROR, (char*)&errcode, &len) == -1) { /* the error number is set to the socket error code. * errno resulting from getsockopt() doesn't reflect the actual @@ -1521,9 +1521,10 @@ static int dev_evcb_sck_ready_stateful (mio_dev_t* dev, int events) else if (events & (MIO_DEV_EVENT_IN | MIO_DEV_EVENT_OUT)) { int x; + x = accept_ssl(rdev); if (x <= -1) return -1; - if (x <= 0) return 0; /* not SSL-accepted yet */ + if (x == 0) return 0; /* not SSL-accepted yet */ if (rdev->tmrjob_index != MIO_TMRIDX_INVALID) { @@ -1575,7 +1576,7 @@ static int dev_evcb_sck_ready_stateless (mio_dev_t* dev, int events) mio_scklen_t len; len = MIO_SIZEOF(errcode); - if (getsockopt (rdev->sck, SOL_SOCKET, SO_ERROR, (char*)&errcode, &len) == -1) + if (getsockopt (rdev->hnd, SOL_SOCKET, SO_ERROR, (char*)&errcode, &len) == -1) { /* the error number is set to the socket error code. * errno resulting from getsockopt() doesn't reflect the actual @@ -1707,12 +1708,12 @@ int mio_dev_sck_timedwritev (mio_dev_sck_t* dev, mio_iovec_t* iov, mio_iolen_t i /* ========================================================================= */ int mio_dev_sck_setsockopt (mio_dev_sck_t* dev, int level, int optname, void* optval, mio_scklen_t optlen) { - return setsockopt(dev->sck, level, optname, optval, optlen); + return setsockopt(dev->hnd, level, optname, optval, optlen); } int mio_dev_sck_getsockopt (mio_dev_sck_t* dev, int level, int optname, void* optval, mio_scklen_t* optlen) { - return getsockopt(dev->sck, level, optname, optval, optlen); + return getsockopt(dev->hnd, level, optname, optval, optlen); } /* ========================================================================= */