diff --git a/moo/kernel/Socket.moo b/moo/kernel/Socket.moo index 8a0a1c8..fb32401 100644 --- a/moo/kernel/Socket.moo +++ b/moo/kernel/Socket.moo @@ -7,6 +7,7 @@ class Socket(Object) from 'sck' method(#primitive) open(domain, type, proto). method(#primitive) _close. method(#primitive) connect(a,b,c). + method(#primitive) endConnect: xxx. } (* TODO: generate these domain and type from the C header *) @@ -68,6 +69,7 @@ extend Socket System addAsyncSemaphore: s2. self connect(1, 2, 3). ] ifCurtailed: [ + ## rollback sa value: s2. ] } @@ -116,6 +118,7 @@ class MyObject(Object) ##s beginRead: xxx. if (result) { + s endConnect: result. 'CONNECTED NOW.............' dump. s asyncRead: [:data | data dump. diff --git a/moo/lib/err.c b/moo/lib/err.c index a8eb5ae..468b0bf 100644 --- a/moo/lib/err.c +++ b/moo/lib/err.c @@ -308,7 +308,7 @@ const moo_ooch_t* moo_geterrmsg (moo_t* moo) void moo_seterrwithsyserr (moo_t* moo, int syserr) { moo_bch_t msgbuf[64]; - strerror_r (errno, msgbuf, MOO_COUNTOF(msgbuf)); + strerror_r (syserr, msgbuf, MOO_COUNTOF(msgbuf)); moo_seterrbfmt (moo, moo_syserr_to_errnum(errno), "%s", msgbuf); } diff --git a/moo/lib/main.c b/moo/lib/main.c index b75da65..4181391 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -1666,6 +1666,7 @@ static void vm_muxwait (moo_t* moo, const moo_ntime_t* dur, moo_vmprim_muxwait_c if (revents & XPOLLERR) mask |= MOO_SEMAPHORE_IO_MASK_ERROR; if (revents & XPOLLHUP) mask |= MOO_SEMAPHORE_IO_MASK_HANGUP; +printf ("먹스 마스크 %d\n", (int)mask); #if defined(USE_DEVPOLL) MOO_ASSERT (moo, xtn->epd.capa > xtn->ev.buf[n].fd); muxwcb (moo, mask, (void*)xtn->epd.ptr[xtn->ev.buf[n].fd]); diff --git a/moo/mod/sck.c b/moo/mod/sck.c index cf810be..67952e6 100644 --- a/moo/mod/sck.c +++ b/moo/mod/sck.c @@ -152,12 +152,55 @@ sin.sin_port = htons(12345); return MOO_PF_SUCCESS; oops_syserr: - errnum = moo_syserr_to_errnum(errno); + moo_seterrwithsyserr (moo, errno); + return MOO_PF_FAILURE; oops: moo_seterrnum (moo, errnum); return MOO_PF_FAILURE; } + +static moo_pfrc_t pf_end_connect (moo_t* moo, moo_ooi_t nargs) +{ + oop_sck_t sck; + int fd; + + sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs); + MOO_PF_CHECK_RCV (moo, + MOO_OOP_IS_POINTER(sck) && + MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) && + MOO_OOP_IS_SMOOI(sck->handle) + ); + + fd = MOO_OOP_TO_SMOOI(sck->handle); + if (fd >= 0) + { + socklen_t len; + int ret; + + len = MOO_SIZEOF(ret); + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*)&ret, &len) == -1) + { + moo_seterrwithsyserr (moo, errno); + return MOO_PF_FAILURE; + } + + if (ret == EINPROGRESS) + { + return MOO_PF_FAILURE; + } + else if (ret != 0) + { + moo_seterrwithsyserr (moo, ret); + return MOO_PF_FAILURE; + } + } + + + MOO_STACK_SETRETTORCV (moo, nargs); + return MOO_PF_SUCCESS; +} + /* ------------------------------------------------------------------------ */ typedef struct fnctab_t fnctab_t; @@ -176,9 +219,10 @@ struct fnctab_t static moo_pfinfo_t pfinfos[] = { - { I, { 'c','l','o','s','e','\0' }, 0, { pf_close_socket, 0, 0 } }, - { I, { 'c','o','n','n','e','c','t','\0' }, 0, { pf_connect, 3, 3 } }, - { I, { 'o','p','e','n','\0' }, 0, { pf_open_socket, 3, 3 } }, + { I, { 'c','l','o','s','e','\0' }, 0, { pf_close_socket, 0, 0 } }, + { I, { 'c','o','n','n','e','c','t','\0' }, 0, { pf_connect, 3, 3 } }, + { I, { 'e','n','d','C','o','n','n','e','c','t',':','\0' }, 0, { pf_end_connect, 1, 1 } }, + { I, { 'o','p','e','n','\0' }, 0, { pf_open_socket, 3, 3 } }, }; /* ------------------------------------------------------------------------ */