added Socket<<endConnect:

This commit is contained in:
hyunghwan.chung 2017-12-18 13:34:47 +00:00
parent 63e34ccf71
commit d8b36bdf66
4 changed files with 53 additions and 5 deletions

View File

@ -7,6 +7,7 @@ class Socket(Object) from 'sck'
method(#primitive) open(domain, type, proto). method(#primitive) open(domain, type, proto).
method(#primitive) _close. method(#primitive) _close.
method(#primitive) connect(a,b,c). method(#primitive) connect(a,b,c).
method(#primitive) endConnect: xxx.
} }
(* TODO: generate these domain and type from the C header *) (* TODO: generate these domain and type from the C header *)
@ -68,6 +69,7 @@ extend Socket
System addAsyncSemaphore: s2. System addAsyncSemaphore: s2.
self connect(1, 2, 3). self connect(1, 2, 3).
] ifCurtailed: [ ] ifCurtailed: [
## rollback
sa value: s2. sa value: s2.
] ]
} }
@ -116,6 +118,7 @@ class MyObject(Object)
##s beginRead: xxx. ##s beginRead: xxx.
if (result) if (result)
{ {
s endConnect: result.
'CONNECTED NOW.............' dump. 'CONNECTED NOW.............' dump.
s asyncRead: [:data | s asyncRead: [:data |
data dump. data dump.

View File

@ -308,7 +308,7 @@ const moo_ooch_t* moo_geterrmsg (moo_t* moo)
void moo_seterrwithsyserr (moo_t* moo, int syserr) void moo_seterrwithsyserr (moo_t* moo, int syserr)
{ {
moo_bch_t msgbuf[64]; 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); moo_seterrbfmt (moo, moo_syserr_to_errnum(errno), "%s", msgbuf);
} }

View File

@ -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 & XPOLLERR) mask |= MOO_SEMAPHORE_IO_MASK_ERROR;
if (revents & XPOLLHUP) mask |= MOO_SEMAPHORE_IO_MASK_HANGUP; if (revents & XPOLLHUP) mask |= MOO_SEMAPHORE_IO_MASK_HANGUP;
printf ("먹스 마스크 %d\n", (int)mask);
#if defined(USE_DEVPOLL) #if defined(USE_DEVPOLL)
MOO_ASSERT (moo, xtn->epd.capa > xtn->ev.buf[n].fd); MOO_ASSERT (moo, xtn->epd.capa > xtn->ev.buf[n].fd);
muxwcb (moo, mask, (void*)xtn->epd.ptr[xtn->ev.buf[n].fd]); muxwcb (moo, mask, (void*)xtn->epd.ptr[xtn->ev.buf[n].fd]);

View File

@ -152,12 +152,55 @@ sin.sin_port = htons(12345);
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
oops_syserr: oops_syserr:
errnum = moo_syserr_to_errnum(errno); moo_seterrwithsyserr (moo, errno);
return MOO_PF_FAILURE;
oops: oops:
moo_seterrnum (moo, errnum); moo_seterrnum (moo, errnum);
return MOO_PF_FAILURE; 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; typedef struct fnctab_t fnctab_t;
@ -176,9 +219,10 @@ struct fnctab_t
static moo_pfinfo_t pfinfos[] = static moo_pfinfo_t pfinfos[] =
{ {
{ I, { 'c','l','o','s','e','\0' }, 0, { pf_close_socket, 0, 0 } }, { 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, { '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, { '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 } },
}; };
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */