mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 07:33:01 +00:00 
			
		
		
		
	Reuse overlapped overhead on windows for something useful.
This commit is contained in:
		| @@ -1484,7 +1484,8 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp to) { | |||||||
|             } |             } | ||||||
|             if (fiber != NULL) { |             if (fiber != NULL) { | ||||||
|                 fiber->ev_in_flight = 0; |                 fiber->ev_in_flight = 0; | ||||||
|                 fiber->ev_bytes = num_bytes_transfered; |                 /* System is done with this, we can reused this data */ | ||||||
|  |                 overlapped->InternalHigh = (ULONG_PTR) num_bytes_transfered; | ||||||
|                 fiber->ev_callback(fiber, result ? JANET_ASYNC_EVENT_COMPLETE : JANET_ASYNC_EVENT_FAILED); |                 fiber->ev_callback(fiber, result ? JANET_ASYNC_EVENT_COMPLETE : JANET_ASYNC_EVENT_FAILED); | ||||||
|             } else { |             } else { | ||||||
|                 janet_free((void *) overlapped); |                 janet_free((void *) overlapped); | ||||||
| @@ -2163,17 +2164,18 @@ void ev_callback_read(JanetFiber *fiber, JanetAsyncEvent event) { | |||||||
|         case JANET_ASYNC_EVENT_FAILED: |         case JANET_ASYNC_EVENT_FAILED: | ||||||
|         case JANET_ASYNC_EVENT_COMPLETE: { |         case JANET_ASYNC_EVENT_COMPLETE: { | ||||||
|             /* Called when read finished */ |             /* Called when read finished */ | ||||||
|             state->bytes_read += fiber->ev_bytes; |             uint32_t ev_bytes = state->overlapped.InternalHigh; | ||||||
|  |             state->bytes_read += ev_bytes; | ||||||
|             if (state->bytes_read == 0 && (state->mode != JANET_ASYNC_READMODE_RECVFROM)) { |             if (state->bytes_read == 0 && (state->mode != JANET_ASYNC_READMODE_RECVFROM)) { | ||||||
|                 janet_schedule(fiber, janet_wrap_nil()); |                 janet_schedule(fiber, janet_wrap_nil()); | ||||||
|                 janet_async_end(fiber); |                 janet_async_end(fiber); | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             janet_buffer_push_bytes(state->buf, state->chunk_buf, fiber->ev_bytes); |             janet_buffer_push_bytes(state->buf, state->chunk_buf, ev_bytes); | ||||||
|             state->bytes_left -= fiber->ev_bytes; |             state->bytes_left -= ev_bytes; | ||||||
|  |  | ||||||
|             if (state->bytes_left == 0 || !state->is_chunk || fiber->ev_bytes == 0) { |             if (state->bytes_left == 0 || !state->is_chunk || ev_bytes == 0) { | ||||||
|                 Janet resume_val; |                 Janet resume_val; | ||||||
| #ifdef JANET_NET | #ifdef JANET_NET | ||||||
|                 if (state->mode == JANET_ASYNC_READMODE_RECVFROM) { |                 if (state->mode == JANET_ASYNC_READMODE_RECVFROM) { | ||||||
| @@ -2412,7 +2414,8 @@ void ev_callback_write(JanetFiber *fiber, JanetAsyncEvent event) { | |||||||
|         case JANET_ASYNC_EVENT_FAILED: |         case JANET_ASYNC_EVENT_FAILED: | ||||||
|         case JANET_ASYNC_EVENT_COMPLETE: { |         case JANET_ASYNC_EVENT_COMPLETE: { | ||||||
|             /* Called when write finished */ |             /* Called when write finished */ | ||||||
|             if (fiber->ev_bytes == 0 && (state->mode != JANET_ASYNC_WRITEMODE_SENDTO)) { |             uint32_t ev_bytes = state->overlapped.InternalHigh; | ||||||
|  |             if (ev_bytes == 0 && (state->mode != JANET_ASYNC_WRITEMODE_SENDTO)) { | ||||||
|                 janet_cancel(fiber, janet_cstringv("disconnect")); |                 janet_cancel(fiber, janet_cstringv("disconnect")); | ||||||
|                 janet_async_end(fiber); |                 janet_async_end(fiber); | ||||||
|                 return; |                 return; | ||||||
|   | |||||||
| @@ -43,7 +43,6 @@ static void fiber_reset(JanetFiber *fiber) { | |||||||
|     fiber->ev_callback = NULL; |     fiber->ev_callback = NULL; | ||||||
|     fiber->ev_state = NULL; |     fiber->ev_state = NULL; | ||||||
|     fiber->ev_stream = NULL; |     fiber->ev_stream = NULL; | ||||||
|     fiber->ev_bytes = 0; |  | ||||||
|     fiber->supervisor_channel = NULL; |     fiber->supervisor_channel = NULL; | ||||||
|     fiber->ev_in_flight = 0; |     fiber->ev_in_flight = 0; | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -1051,7 +1051,6 @@ static const uint8_t *unmarshal_one_fiber( | |||||||
|     fiber->sched_id = 0; |     fiber->sched_id = 0; | ||||||
|     fiber->supervisor_channel = NULL; |     fiber->supervisor_channel = NULL; | ||||||
|     fiber->ev_state = NULL; |     fiber->ev_state = NULL; | ||||||
|     fiber->ev_bytes = 0; |  | ||||||
|     fiber->ev_callback = NULL; |     fiber->ev_callback = NULL; | ||||||
|     fiber->ev_stream = NULL; |     fiber->ev_stream = NULL; | ||||||
|     fiber->ev_in_flight = 0; |     fiber->ev_in_flight = 0; | ||||||
|   | |||||||
| @@ -927,7 +927,6 @@ struct JanetFiber { | |||||||
|     JanetStream *ev_stream; /* which stream we are waiting on */ |     JanetStream *ev_stream; /* which stream we are waiting on */ | ||||||
|     void *ev_state; /* Extra data for ev callback state. On windows, first element must be OVERLAPPED. */ |     void *ev_state; /* Extra data for ev callback state. On windows, first element must be OVERLAPPED. */ | ||||||
|     void *supervisor_channel; /* Channel to push self to when complete */ |     void *supervisor_channel; /* Channel to push self to when complete */ | ||||||
|     uint32_t ev_bytes; /* Number of bytes for completion event */ |  | ||||||
|     int ev_in_flight; /* If overlapped operation is in flight */ |     int ev_in_flight; /* If overlapped operation is in flight */ | ||||||
| #endif | #endif | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose