mirror of
https://github.com/janet-lang/janet
synced 2025-01-14 09:25:41 +00:00
Try again for windows build.
This commit is contained in:
parent
7d0b1955a2
commit
d50c4ef6da
130
src/core/ev.c
130
src/core/ev.c
@ -1239,10 +1239,10 @@ JanetAsyncStatus ev_machine_read(JanetListenerState *s, JanetAsyncEvent event) {
|
|||||||
state->wbuf.buf = state->chunk_buf;
|
state->wbuf.buf = state->chunk_buf;
|
||||||
if (state->mode == JANET_ASYNC_READMODE_RECVFROM) {
|
if (state->mode == JANET_ASYNC_READMODE_RECVFROM) {
|
||||||
status = WSARecvFrom((SOCKET) s->stream->handle, &state->wbuf, 1,
|
status = WSARecvFrom((SOCKET) s->stream->handle, &state->wbuf, 1,
|
||||||
NULL, &state->flags, &state->from, &state->fromlen, &state->overlapped, NULL);
|
NULL, &state->flags, &state->from, &state->fromlen, &state->overlapped, NULL);
|
||||||
} else {
|
} else {
|
||||||
status = WSARecv((SOCKET) s->stream->handle, &state->wbuf, 1,
|
status = WSARecv((SOCKET) s->stream->handle, &state->wbuf, 1,
|
||||||
NULL, &state->flags, &state->overlapped, NULL);
|
NULL, &state->flags, &state->overlapped, NULL);
|
||||||
}
|
}
|
||||||
if (status && (WSA_IO_PENDING != WSAGetLastError())) {
|
if (status && (WSA_IO_PENDING != WSAGetLastError())) {
|
||||||
janet_cancel(s->fiber, janet_ev_lasterr());
|
janet_cancel(s->fiber, janet_ev_lasterr());
|
||||||
@ -1262,78 +1262,78 @@ JanetAsyncStatus ev_machine_read(JanetListenerState *s, JanetAsyncEvent event) {
|
|||||||
#else
|
#else
|
||||||
case JANET_ASYNC_EVENT_ERR:
|
case JANET_ASYNC_EVENT_ERR:
|
||||||
case JANET_ASYNC_EVENT_HUP: {
|
case JANET_ASYNC_EVENT_HUP: {
|
||||||
if (state->bytes_read) {
|
if (state->bytes_read) {
|
||||||
janet_schedule(s->fiber, janet_wrap_buffer(state->buf));
|
janet_schedule(s->fiber, janet_wrap_buffer(state->buf));
|
||||||
} else {
|
} else {
|
||||||
janet_schedule(s->fiber, janet_wrap_nil());
|
janet_schedule(s->fiber, janet_wrap_nil());
|
||||||
}
|
|
||||||
return JANET_ASYNC_STATUS_DONE;
|
|
||||||
}
|
}
|
||||||
|
return JANET_ASYNC_STATUS_DONE;
|
||||||
|
}
|
||||||
case JANET_ASYNC_EVENT_READ:
|
case JANET_ASYNC_EVENT_READ:
|
||||||
/* Read in bytes */
|
/* Read in bytes */
|
||||||
{
|
{
|
||||||
JanetBuffer *buffer = state->buf;
|
JanetBuffer *buffer = state->buf;
|
||||||
int32_t bytes_left = state->bytes_left;
|
int32_t bytes_left = state->bytes_left;
|
||||||
janet_buffer_extra(buffer, bytes_left);
|
janet_buffer_extra(buffer, bytes_left);
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
#ifdef JANET_NET
|
#ifdef JANET_NET
|
||||||
char saddr[256];
|
char saddr[256];
|
||||||
socklen_t socklen = sizeof(saddr);
|
socklen_t socklen = sizeof(saddr);
|
||||||
#endif
|
#endif
|
||||||
do {
|
do {
|
||||||
#ifdef JANET_NET
|
#ifdef JANET_NET
|
||||||
if (state->mode == JANET_ASYNC_READMODE_RECVFROM) {
|
if (state->mode == JANET_ASYNC_READMODE_RECVFROM) {
|
||||||
nread = recvfrom(s->stream->handle, buffer->data + buffer->count, bytes_left, state->flags,
|
nread = recvfrom(s->stream->handle, buffer->data + buffer->count, bytes_left, state->flags,
|
||||||
(struct sockaddr *)&saddr, &socklen);
|
(struct sockaddr *)&saddr, &socklen);
|
||||||
} else if (state->mode == JANET_ASYNC_READMODE_RECV) {
|
} else if (state->mode == JANET_ASYNC_READMODE_RECV) {
|
||||||
nread = recv(s->stream->handle, buffer->data + buffer->count, bytes_left, state->flags);
|
nread = recv(s->stream->handle, buffer->data + buffer->count, bytes_left, state->flags);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
nread = read(s->stream->handle, buffer->data + buffer->count, bytes_left);
|
nread = read(s->stream->handle, buffer->data + buffer->count, bytes_left);
|
||||||
}
|
|
||||||
} while (nread == -1 && errno == EINTR);
|
|
||||||
|
|
||||||
/* Check for errors - special case errors that can just be waited on to fix */
|
|
||||||
if (nread == -1) {
|
|
||||||
if (errno == EAGAIN || errno == EWOULDBLOCK) break;
|
|
||||||
janet_cancel(s->fiber, janet_ev_lasterr());
|
|
||||||
return JANET_ASYNC_STATUS_DONE;
|
|
||||||
}
|
}
|
||||||
|
} while (nread == -1 && errno == EINTR);
|
||||||
|
|
||||||
/* Only allow 0-length packets in recv-from. In stream protocols, a zero length packet is EOS. */
|
/* Check for errors - special case errors that can just be waited on to fix */
|
||||||
state->bytes_read += nread;
|
if (nread == -1) {
|
||||||
if (state->bytes_read == 0 && (state->mode != JANET_ASYNC_READMODE_RECVFROM)) {
|
if (errno == EAGAIN || errno == EWOULDBLOCK) break;
|
||||||
janet_schedule(s->fiber, janet_wrap_nil());
|
janet_cancel(s->fiber, janet_ev_lasterr());
|
||||||
return JANET_ASYNC_STATUS_DONE;
|
return JANET_ASYNC_STATUS_DONE;
|
||||||
}
|
|
||||||
|
|
||||||
/* Increment buffer counts */
|
|
||||||
buffer->count += nread;
|
|
||||||
bytes_left -= nread;
|
|
||||||
state->bytes_left = bytes_left;
|
|
||||||
|
|
||||||
/* Resume if done */
|
|
||||||
if (!state->is_chunk || bytes_left == 0 || nread == 0) {
|
|
||||||
Janet resume_val;
|
|
||||||
#ifdef JANET_NET
|
|
||||||
if (state->mode == JANET_ASYNC_READMODE_RECVFROM) {
|
|
||||||
void *abst = janet_abstract(&janet_address_type, socklen);
|
|
||||||
memcpy(abst, &saddr, socklen);
|
|
||||||
resume_val = janet_wrap_abstract(abst);
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
resume_val = janet_wrap_buffer(buffer);
|
|
||||||
}
|
|
||||||
janet_schedule(s->fiber, resume_val);
|
|
||||||
return JANET_ASYNC_STATUS_DONE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
/* Only allow 0-length packets in recv-from. In stream protocols, a zero length packet is EOS. */
|
||||||
|
state->bytes_read += nread;
|
||||||
|
if (state->bytes_read == 0 && (state->mode != JANET_ASYNC_READMODE_RECVFROM)) {
|
||||||
|
janet_schedule(s->fiber, janet_wrap_nil());
|
||||||
|
return JANET_ASYNC_STATUS_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Increment buffer counts */
|
||||||
|
buffer->count += nread;
|
||||||
|
bytes_left -= nread;
|
||||||
|
state->bytes_left = bytes_left;
|
||||||
|
|
||||||
|
/* Resume if done */
|
||||||
|
if (!state->is_chunk || bytes_left == 0 || nread == 0) {
|
||||||
|
Janet resume_val;
|
||||||
|
#ifdef JANET_NET
|
||||||
|
if (state->mode == JANET_ASYNC_READMODE_RECVFROM) {
|
||||||
|
void *abst = janet_abstract(&janet_address_type, socklen);
|
||||||
|
memcpy(abst, &saddr, socklen);
|
||||||
|
resume_val = janet_wrap_abstract(abst);
|
||||||
|
} else
|
||||||
#endif
|
#endif
|
||||||
}
|
{
|
||||||
return JANET_ASYNC_STATUS_NOT_DONE;
|
resume_val = janet_wrap_buffer(buffer);
|
||||||
|
}
|
||||||
|
janet_schedule(s->fiber, resume_val);
|
||||||
|
return JANET_ASYNC_STATUS_DONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return JANET_ASYNC_STATUS_NOT_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void janet_ev_read_generic(JanetStream *stream, JanetBuffer *buf, int32_t nbytes, int is_chunked, JanetReadMode mode, int flags) {
|
static void janet_ev_read_generic(JanetStream *stream, JanetBuffer *buf, int32_t nbytes, int is_chunked, JanetReadMode mode, int flags) {
|
||||||
@ -1431,7 +1431,7 @@ JanetAsyncStatus ev_machine_write(JanetListenerState *s, JanetAsyncEvent event)
|
|||||||
break;
|
break;
|
||||||
case JANET_ASYNC_EVENT_USER: {
|
case JANET_ASYNC_EVENT_USER: {
|
||||||
/* Begin write */
|
/* Begin write */
|
||||||
int32_t start, len;
|
int32_t len;
|
||||||
const uint8_t *bytes;
|
const uint8_t *bytes;
|
||||||
if (state->is_buffer) {
|
if (state->is_buffer) {
|
||||||
/* If buffer, convert to string. */
|
/* If buffer, convert to string. */
|
||||||
@ -1555,7 +1555,7 @@ static void janet_ev_write_generic(JanetStream *stream, void *buf, void *dest_ab
|
|||||||
state->mode = mode;
|
state->mode = mode;
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef JANET_WINDOWS
|
||||||
state->flags = (DWORD) flags;
|
state->flags = (DWORD) flags;
|
||||||
net_machine_write((JanetListenerState *) state, JANET_ASYNC_EVENT_USER);
|
ev_machine_write((JanetListenerState *) state, JANET_ASYNC_EVENT_USER);
|
||||||
#else
|
#else
|
||||||
state->start = 0;
|
state->start = 0;
|
||||||
state->flags = flags;
|
state->flags = flags;
|
||||||
|
@ -57,6 +57,7 @@ const JanetAbstractType janet_address_type = {
|
|||||||
|
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef JANET_WINDOWS
|
||||||
#define JSOCKCLOSE(x) closesocket((SOCKET) x)
|
#define JSOCKCLOSE(x) closesocket((SOCKET) x)
|
||||||
|
#define JSOCKDEFAULT INVALID_SOCKET
|
||||||
#define JSOCKVALID(x) ((x) != INVALID_SOCKET)
|
#define JSOCKVALID(x) ((x) != INVALID_SOCKET)
|
||||||
#define JSock SOCKET
|
#define JSock SOCKET
|
||||||
#define JSOCKFLAGS 0
|
#define JSOCKFLAGS 0
|
||||||
@ -72,7 +73,7 @@ const JanetAbstractType janet_address_type = {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static JanetStream *make_stream(JanetHandle handle, uint32_t flags);
|
static JanetStream *make_stream(JSock handle, uint32_t flags);
|
||||||
|
|
||||||
/* We pass this flag to all send calls to prevent sigpipe */
|
/* We pass this flag to all send calls to prevent sigpipe */
|
||||||
#ifndef MSG_NOSIGNAL
|
#ifndef MSG_NOSIGNAL
|
||||||
@ -172,7 +173,7 @@ static int net_sched_accept_impl(NetStateAccept *state, Janet *err) {
|
|||||||
SOCKET lsock = (SOCKET) state->lstream->handle;
|
SOCKET lsock = (SOCKET) state->lstream->handle;
|
||||||
SOCKET asock = WSASocketW(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
|
SOCKET asock = WSASocketW(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
|
||||||
if (asock == INVALID_SOCKET) {
|
if (asock == INVALID_SOCKET) {
|
||||||
*err = net_lasterr();
|
*err = ev_lasterr();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
JanetStream *astream = make_stream(asock, JANET_STREAM_READABLE | JANET_STREAM_WRITABLE);
|
JanetStream *astream = make_stream(asock, JANET_STREAM_READABLE | JANET_STREAM_WRITABLE);
|
||||||
@ -181,7 +182,7 @@ static int net_sched_accept_impl(NetStateAccept *state, Janet *err) {
|
|||||||
if (FALSE == AcceptEx(lsock, asock, state->buf, 0, socksize, socksize, NULL, &state->overlapped)) {
|
if (FALSE == AcceptEx(lsock, asock, state->buf, 0, socksize, socksize, NULL, &state->overlapped)) {
|
||||||
int code = WSAGetLastError();
|
int code = WSAGetLastError();
|
||||||
if (code == WSA_IO_PENDING) return 0; /* indicates io is happening async */
|
if (code == WSA_IO_PENDING) return 0; /* indicates io is happening async */
|
||||||
*err = net_lasterr();
|
*err = ev_lasterr();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -614,8 +615,8 @@ static const JanetMethod net_stream_methods[] = {
|
|||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
static JanetStream *make_stream(JanetHandle handle, uint32_t flags) {
|
static JanetStream *make_stream(JSock handle, uint32_t flags) {
|
||||||
return janet_stream(handle, flags | JANET_STREAM_SOCKET, net_stream_methods);
|
return janet_stream((JanetHandle) handle, flags | JANET_STREAM_SOCKET, net_stream_methods);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg net_cfuns[] = {
|
static const JanetReg net_cfuns[] = {
|
||||||
|
Loading…
Reference in New Issue
Block a user