X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=src%2Fmeshlink.c;h=22f5220d4beebe6c19d6612d45923602e0e78061;hp=55b1e04fcd7d807d5e0304a2887026322e1f98c3;hb=ee6ddcdc21976e1db0a8ee414d61fa9304459886;hpb=8d4b96efb7955eaa96174af4804597f92e124041 diff --git a/src/meshlink.c b/src/meshlink.c index 55b1e04f..22f5220d 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1659,7 +1659,12 @@ bool meshlink_start(meshlink_handle_t *mesh) { event_loop_start(&mesh->loop); - if(pthread_create(&mesh->thread, NULL, meshlink_main_loop, mesh) != 0) { + // Ensure we have a decent amount of stack space. Musl's default of 80 kB is too small. + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, 1024 * 1024); + + if(pthread_create(&mesh->thread, &attr, meshlink_main_loop, mesh) != 0) { logger(mesh, MESHLINK_DEBUG, "Could not start thread: %s\n", strerror(errno)); memset(&mesh->thread, 0, sizeof(mesh)->thread); meshlink_errno = MESHLINK_EINTERNAL; @@ -3465,7 +3470,7 @@ static bool aio_finish_one(meshlink_handle_t *mesh, meshlink_channel_t *channel, if(aio->data) { if(aio->cb.buffer) { - aio->cb.buffer(mesh, channel, aio->data, aio->len, aio->priv); + aio->cb.buffer(mesh, channel, aio->data, aio->done, aio->priv); } } else { if(aio->cb.fd) { @@ -3675,6 +3680,11 @@ static void channel_poll(struct utcp_connection *connection, size_t len) { if(aio->data) { sent = utcp_send(connection, (char *)aio->data + aio->done, todo); } else { + /* Limit the amount we read at once to avoid stack overflows */ + if(todo > 65536) { + todo = 65536; + } + char buf[todo]; ssize_t result = read(aio->fd, buf, todo); @@ -3701,7 +3711,7 @@ static void channel_poll(struct utcp_connection *connection, size_t len) { if(sent != (ssize_t)todo) { /* We should never get a partial send at this point */ - assert(sent < 0); + assert(sent <= 0); /* Sending failed, abort all outstanding AIO buffers and send a poll callback. */ if(!aio_abort(mesh, channel, &channel->aio_send)) {