@@ -2481,6 +2481,31 @@ typedef struct {
2481
2481
#endif
2482
2482
} StateWrite ;
2483
2483
2484
+ static JanetAsyncStatus handle_connect (JanetListenerState * s ) {
2485
+ #ifdef JANET_WINDOWS
2486
+ int res = 0 ;
2487
+ int size = sizeof (res );
2488
+ int r = getsockopt ((SOCKET )s -> stream -> handle , SOL_SOCKET , SO_ERROR , (char * )& res , & size );
2489
+ #else
2490
+ int res = 0 ;
2491
+ socklen_t size = sizeof res ;
2492
+ int r = getsockopt (s -> stream -> handle , SOL_SOCKET , SO_ERROR , & res , & size );
2493
+ #endif
2494
+ if (r == 0 ) {
2495
+ if (res == 0 ) {
2496
+ janet_schedule (s -> fiber , janet_wrap_abstract (s -> stream ));
2497
+ } else {
2498
+ janet_cancel (s -> fiber , janet_cstringv (strerror (res )));
2499
+ // TODO help needed. janet_stream_close(s->stream);
2500
+ }
2501
+ return JANET_ASYNC_STATUS_DONE ;
2502
+ } else {
2503
+ // TODO panic? assert?
2504
+ return JANET_ASYNC_STATUS_NOT_DONE ;
2505
+ }
2506
+ }
2507
+
2508
+
2484
2509
JanetAsyncStatus ev_machine_write (JanetListenerState * s , JanetAsyncEvent event ) {
2485
2510
StateWrite * state = (StateWrite * ) s ;
2486
2511
switch (event ) {
@@ -2512,21 +2537,7 @@ JanetAsyncStatus ev_machine_write(JanetListenerState *s, JanetAsyncEvent event)
2512
2537
case JANET_ASYNC_EVENT_USER : {
2513
2538
#ifdef JANET_NET
2514
2539
if (state -> mode == JANET_ASYNC_WRITEMODE_CONNECT ) {
2515
- int res = 0 ;
2516
- int size = sizeof res ;
2517
- int r = getsockopt ((SOCKET )s -> stream -> handle , SOL_SOCKET , SO_ERROR , (char * )& res , & size );
2518
- if (r == 0 ) {
2519
- if (res == 0 ) {
2520
- janet_schedule (s -> fiber , janet_wrap_abstract (s -> stream ));
2521
- } else {
2522
- // TODO JSOCKCLOSE(s->sock) but is in net.c;
2523
- janet_cancel (s -> fiber , janet_cstringv (strerror (res )));
2524
- }
2525
- return JANET_ASYNC_STATUS_DONE ;
2526
- } else {
2527
- // TODO panic? assert?
2528
- return JANET_ASYNC_STATUS_NOT_DONE ;
2529
- }
2540
+ return handle_connect (s );
2530
2541
}
2531
2542
#endif
2532
2543
/* Begin write */
@@ -2594,21 +2605,7 @@ JanetAsyncStatus ev_machine_write(JanetListenerState *s, JanetAsyncEvent event)
2594
2605
case JANET_ASYNC_EVENT_WRITE : {
2595
2606
#ifdef JANET_NET
2596
2607
if (state -> mode == JANET_ASYNC_WRITEMODE_CONNECT ) {
2597
- int res = 0 ;
2598
- socklen_t size = sizeof res ;
2599
- int r = getsockopt (s -> stream -> handle , SOL_SOCKET , SO_ERROR , & res , & size );
2600
- if (r == 0 ) {
2601
- if (res == 0 ) {
2602
- janet_schedule (s -> fiber , janet_wrap_abstract (s -> stream ));
2603
- } else {
2604
- // TODO JSOCKCLOSE(s->sock) but is in net.c;
2605
- janet_cancel (s -> fiber , janet_cstringv (strerror (res )));
2606
- }
2607
- return JANET_ASYNC_STATUS_DONE ;
2608
- } else {
2609
- // TODO panic? assert?
2610
- return JANET_ASYNC_STATUS_NOT_DONE ;
2611
- }
2608
+ return handle_connect (s );
2612
2609
}
2613
2610
#endif
2614
2611
int32_t start , len ;
0 commit comments