@@ -2456,7 +2456,8 @@ void janet_ev_recvfrom(JanetStream *stream, JanetBuffer *buf, int32_t nbytes, in
2456
2456
typedef enum {
2457
2457
JANET_ASYNC_WRITEMODE_WRITE ,
2458
2458
JANET_ASYNC_WRITEMODE_SEND ,
2459
- JANET_ASYNC_WRITEMODE_SENDTO
2459
+ JANET_ASYNC_WRITEMODE_SENDTO ,
2460
+ JANET_ASYNC_WRITEMODE_CONNECT
2460
2461
} JanetWriteMode ;
2461
2462
2462
2463
typedef struct {
@@ -2509,6 +2510,25 @@ JanetAsyncStatus ev_machine_write(JanetListenerState *s, JanetAsyncEvent event)
2509
2510
}
2510
2511
break ;
2511
2512
case JANET_ASYNC_EVENT_USER : {
2513
+ #ifdef JANET_NET
2514
+ 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
+ }
2530
+ }
2531
+ #endif
2512
2532
/* Begin write */
2513
2533
int32_t len ;
2514
2534
const uint8_t * bytes ;
@@ -2572,6 +2592,25 @@ JanetAsyncStatus ev_machine_write(JanetListenerState *s, JanetAsyncEvent event)
2572
2592
janet_cancel (s -> fiber , janet_cstringv ("stream hup" ));
2573
2593
return JANET_ASYNC_STATUS_DONE ;
2574
2594
case JANET_ASYNC_EVENT_WRITE : {
2595
+ #ifdef JANET_NET
2596
+ 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
+ }
2612
+ }
2613
+ #endif
2575
2614
int32_t start , len ;
2576
2615
const uint8_t * bytes ;
2577
2616
start = state -> start ;
@@ -2674,6 +2713,10 @@ void janet_ev_sendto_buffer(JanetStream *stream, JanetBuffer *buf, void *dest, i
2674
2713
void janet_ev_sendto_string (JanetStream * stream , JanetString str , void * dest , int flags ) {
2675
2714
janet_ev_write_generic (stream , (void * ) str , dest , JANET_ASYNC_WRITEMODE_SENDTO , 0 , flags );
2676
2715
}
2716
+
2717
+ void janet_ev_connect (JanetStream * stream , int flags ) {
2718
+ janet_ev_write_generic (stream , NULL , NULL , JANET_ASYNC_WRITEMODE_CONNECT , 0 , flags );
2719
+ }
2677
2720
#endif
2678
2721
2679
2722
/* For a pipe ID */
0 commit comments