mirror of
https://github.com/janet-lang/janet
synced 2024-09-29 23:40:40 +00:00
Fix issues with #282
Bad handling of write errors, as well as janet_root_fiber().
This commit is contained in:
parent
f4a46ba6ea
commit
0df220780a
@ -26,6 +26,8 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@ -146,6 +148,9 @@ JANET_THREAD_LOCAL int janet_vm_loop_count;
|
|||||||
void janet_net_markloop(void) {
|
void janet_net_markloop(void) {
|
||||||
for (int i = 0; i < janet_vm_loop_count; i++) {
|
for (int i = 0; i < janet_vm_loop_count; i++) {
|
||||||
JanetLoopFD lfd = janet_vm_loopfds[i];
|
JanetLoopFD lfd = janet_vm_loopfds[i];
|
||||||
|
if (lfd.fiber != NULL) {
|
||||||
|
janet_mark(janet_wrap_fiber(lfd.fiber));
|
||||||
|
}
|
||||||
janet_mark(janet_wrap_abstract(lfd.stream));
|
janet_mark(janet_wrap_abstract(lfd.stream));
|
||||||
switch (lfd.event_type) {
|
switch (lfd.event_type) {
|
||||||
default:
|
default:
|
||||||
@ -175,9 +180,6 @@ static int janet_loop_schedule(JanetLoopFD lfd) {
|
|||||||
}
|
}
|
||||||
int index = janet_vm_loop_count;
|
int index = janet_vm_loop_count;
|
||||||
janet_vm_loopfds[janet_vm_loop_count++] = lfd;
|
janet_vm_loopfds[janet_vm_loop_count++] = lfd;
|
||||||
if (NULL != lfd.fiber) {
|
|
||||||
janet_gcroot(janet_wrap_fiber(lfd.fiber));
|
|
||||||
}
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,9 +276,10 @@ static size_t janet_loop_event(size_t index) {
|
|||||||
if (start < len) {
|
if (start < len) {
|
||||||
int32_t nbytes = len - start;
|
int32_t nbytes = len - start;
|
||||||
ssize_t nwrote;
|
ssize_t nwrote;
|
||||||
|
errno = 0;
|
||||||
do {
|
do {
|
||||||
nwrote = write(fd, bytes + start, nbytes);
|
nwrote = write(fd, bytes + start, nbytes);
|
||||||
} while (nwrote == EINTR);
|
} while (errno == EINTR);
|
||||||
if (nwrote > 0) {
|
if (nwrote > 0) {
|
||||||
start += nwrote;
|
start += nwrote;
|
||||||
} else {
|
} else {
|
||||||
@ -422,7 +425,7 @@ static struct addrinfo *janet_get_addrinfo(Janet *argv, int32_t offset) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static Janet cfun_net_connect(int32_t argc, Janet *argv) {
|
static Janet cfun_net_connect(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 2);
|
janet_arity(argc, 2, -1);
|
||||||
|
|
||||||
struct addrinfo *ai = janet_get_addrinfo(argv, 0);
|
struct addrinfo *ai = janet_get_addrinfo(argv, 0);
|
||||||
|
|
||||||
@ -433,6 +436,16 @@ static Janet cfun_net_connect(int32_t argc, Janet *argv) {
|
|||||||
janet_panic("could not create socket");
|
janet_panic("could not create socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set socket opts */
|
||||||
|
/*for (int32_t argi = 1; argi < argc; argi++) {
|
||||||
|
const uint8_t *kw = janet_getkeyword(argv, argi);
|
||||||
|
if (janet_cstrcmp(kw, "no-delay")) {
|
||||||
|
int one = 1;
|
||||||
|
setsockopt(sock, SOL_TCP, TCP_NODELAY, &one, sizeof(one));
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
/* Connect to socket */
|
/* Connect to socket */
|
||||||
int status = connect(sock, ai->ai_addr, ai->ai_addrlen);
|
int status = connect(sock, ai->ai_addr, ai->ai_addrlen);
|
||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai);
|
||||||
|
@ -1280,7 +1280,7 @@ JanetSignal janet_continue(JanetFiber *fiber, Janet in, Janet *out) {
|
|||||||
Janet *old_vm_return_reg = janet_vm_return_reg;
|
Janet *old_vm_return_reg = janet_vm_return_reg;
|
||||||
|
|
||||||
/* Setup fiber */
|
/* Setup fiber */
|
||||||
if (oldn == 0) janet_vm_root_fiber = fiber;
|
if (janet_vm_root_fiber == NULL) janet_vm_root_fiber = fiber;
|
||||||
janet_vm_fiber = fiber;
|
janet_vm_fiber = fiber;
|
||||||
janet_gcroot(janet_wrap_fiber(fiber));
|
janet_gcroot(janet_wrap_fiber(fiber));
|
||||||
janet_fiber_set_status(fiber, JANET_STATUS_ALIVE);
|
janet_fiber_set_status(fiber, JANET_STATUS_ALIVE);
|
||||||
@ -1306,7 +1306,7 @@ JanetSignal janet_continue(JanetFiber *fiber, Janet in, Janet *out) {
|
|||||||
janet_gcunroot(janet_wrap_fiber(fiber));
|
janet_gcunroot(janet_wrap_fiber(fiber));
|
||||||
|
|
||||||
/* Restore global state */
|
/* Restore global state */
|
||||||
if (oldn == 0) janet_vm_root_fiber = NULL;
|
if (janet_vm_root_fiber == fiber) janet_vm_root_fiber = NULL;
|
||||||
janet_vm_gc_suspend = handle;
|
janet_vm_gc_suspend = handle;
|
||||||
janet_vm_fiber = old_vm_fiber;
|
janet_vm_fiber = old_vm_fiber;
|
||||||
janet_vm_stackn = oldn;
|
janet_vm_stackn = oldn;
|
||||||
@ -1377,6 +1377,7 @@ int janet_init(void) {
|
|||||||
/* Fibers */
|
/* Fibers */
|
||||||
janet_vm_fiber = NULL;
|
janet_vm_fiber = NULL;
|
||||||
janet_vm_root_fiber = NULL;
|
janet_vm_root_fiber = NULL;
|
||||||
|
janet_vm_stackn = 0;
|
||||||
/* Threads */
|
/* Threads */
|
||||||
#ifdef JANET_THREADS
|
#ifdef JANET_THREADS
|
||||||
janet_threads_init();
|
janet_threads_init();
|
||||||
|
Loading…
Reference in New Issue
Block a user