accept and accept-nonblocking now set the port-id to a string
representing the incoming address like "nnn.nnn.nnn.nnn:pppp"
This commit is contained in:
parent
25344fa1d0
commit
bdd81e2b05
|
@ -23,6 +23,8 @@
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(let f ()
|
(let f ()
|
||||||
(let-values ([(op ip) (accept-connection s)])
|
(let-values ([(op ip) (accept-connection s)])
|
||||||
|
(printf "Connection from address ~a\n"
|
||||||
|
op)
|
||||||
(let ([op (transcoded-port op (native-transcoder))]
|
(let ([op (transcoded-port op (native-transcoder))]
|
||||||
[ip (transcoded-port ip (native-transcoder))])
|
[ip (transcoded-port ip (native-transcoder))])
|
||||||
(display "What's your name? " op)
|
(display "What's your name? " op)
|
||||||
|
|
|
@ -1206,7 +1206,10 @@
|
||||||
#| 20 |# "invalid file name"
|
#| 20 |# "invalid file name"
|
||||||
#| 21 |# "non-blocking operation would block"
|
#| 21 |# "non-blocking operation would block"
|
||||||
#| 22 |# "broken pipe (e.g., writing to a closed process or socket)"
|
#| 22 |# "broken pipe (e.g., writing to a closed process or socket)"
|
||||||
#| 23 |# "connection refused"))
|
#| 23 |# "connection refused"
|
||||||
|
#| 24 |# "not a socket"
|
||||||
|
#| 25 |# "not enough memory to perform operation"
|
||||||
|
))
|
||||||
|
|
||||||
(define (io-error who id err . other-conditions)
|
(define (io-error who id err . other-conditions)
|
||||||
(let ([err (fxnot err)])
|
(let ([err (fxnot err)])
|
||||||
|
@ -2136,7 +2139,6 @@
|
||||||
(define out-queue '())
|
(define out-queue '())
|
||||||
(define in-queue '())
|
(define in-queue '())
|
||||||
|
|
||||||
|
|
||||||
(define (process-events)
|
(define (process-events)
|
||||||
(if (null? out-queue)
|
(if (null? out-queue)
|
||||||
(if (null? in-queue)
|
(if (null? in-queue)
|
||||||
|
@ -2241,12 +2243,22 @@
|
||||||
|
|
||||||
|
|
||||||
(define (do-accept-connection s who blocking?)
|
(define (do-accept-connection s who blocking?)
|
||||||
|
(define (make-socket-info x)
|
||||||
|
(unless (= (bytevector-length x) 16)
|
||||||
|
(error who "BUG: unexpected return value" x))
|
||||||
|
(format "~s.~s.~s.~s:~s"
|
||||||
|
(bytevector-u8-ref x 4)
|
||||||
|
(bytevector-u8-ref x 5)
|
||||||
|
(bytevector-u8-ref x 6)
|
||||||
|
(bytevector-u8-ref x 7)
|
||||||
|
(+ (* 256 (bytevector-u8-ref x 2))
|
||||||
|
(bytevector-u8-ref x 3))))
|
||||||
(unless (tcp-server? s)
|
(unless (tcp-server? s)
|
||||||
(die who "not a tcp server" s))
|
(die who "not a tcp server" s))
|
||||||
(let ([fd (tcp-server-fd s)])
|
(let ([fd (tcp-server-fd s)] [bv (make-bytevector 16)])
|
||||||
(unless fd
|
(unless fd
|
||||||
(die who "server is closed" s))
|
(die who "server is closed" s))
|
||||||
(let ([sock (foreign-call "ikrt_accept" fd)])
|
(let ([sock (foreign-call "ikrt_accept" fd bv)])
|
||||||
(cond
|
(cond
|
||||||
[(eq? sock EAGAIN-error-code)
|
[(eq? sock EAGAIN-error-code)
|
||||||
(call/cc
|
(call/cc
|
||||||
|
@ -2254,8 +2266,10 @@
|
||||||
(add-io-event fd k 'r)
|
(add-io-event fd k 'r)
|
||||||
(process-events)))
|
(process-events)))
|
||||||
(do-accept-connection s who blocking?)]
|
(do-accept-connection s who blocking?)]
|
||||||
|
[(< sock 0)
|
||||||
|
(io-error who s sock)]
|
||||||
[else
|
[else
|
||||||
(socket->ports sock who #f blocking?)]))))
|
(socket->ports sock who (make-socket-info bv) blocking?)]))))
|
||||||
|
|
||||||
(define (accept-connection s)
|
(define (accept-connection s)
|
||||||
(do-accept-connection s 'accept-connection #t))
|
(do-accept-connection s 'accept-connection #t))
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
1444
|
1445
|
||||||
|
|
|
@ -59,6 +59,8 @@ ikrt_io_error(){
|
||||||
case EAGAIN : return fix(-22); /* hardcoded in ikarus.io.ss */
|
case EAGAIN : return fix(-22); /* hardcoded in ikarus.io.ss */
|
||||||
case EPIPE : return fix(-23);
|
case EPIPE : return fix(-23);
|
||||||
case ECONNREFUSED : return fix(-24);
|
case ECONNREFUSED : return fix(-24);
|
||||||
|
case ENOTSOCK : return fix(-25);
|
||||||
|
case ENOBUFS : return fix(-26);
|
||||||
}
|
}
|
||||||
return fix(-1);
|
return fix(-1);
|
||||||
}
|
}
|
||||||
|
@ -251,12 +253,37 @@ ikrt_listen(ikptr port, ikpcb* pcb){
|
||||||
return fix(sock);
|
return fix(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
not used
|
||||||
ikptr
|
ikptr
|
||||||
ikrt_accept(ikptr s, ikpcb* pcb){
|
ikrt_getsockname(ikptr s, ikpcb* pcb){
|
||||||
int sock = accept(unfix(s), NULL, NULL);
|
socklen_t size = sizeof(struct sockaddr);
|
||||||
|
ikptr bv = ik_safe_alloc(pcb, align(disp_bytevector_data+size))
|
||||||
|
+ bytevector_tag;
|
||||||
|
int r = getsockname(unfix(s),
|
||||||
|
(struct sockaddr*)(bv+off_bytevector_data),
|
||||||
|
&size);
|
||||||
|
if(r == 0){
|
||||||
|
ref(bv, off_bytevector_length) = fix(size);
|
||||||
|
return bv;
|
||||||
|
} else {
|
||||||
|
return ikrt_io_error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ikptr
|
||||||
|
ikrt_accept(ikptr s, ikptr bv, ikpcb* pcb){
|
||||||
|
socklen_t addrlen = unfix(ref(bv, off_bytevector_length));
|
||||||
|
int sock = accept(unfix(s),
|
||||||
|
(struct sockaddr*) (bv+off_bytevector_data),
|
||||||
|
&addrlen);
|
||||||
if(sock < 0){
|
if(sock < 0){
|
||||||
return ikrt_io_error();
|
return ikrt_io_error();
|
||||||
}
|
}
|
||||||
|
ref(bv, off_bytevector_length) = fix(addrlen);
|
||||||
return fix(sock);
|
return fix(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,3 +314,6 @@ ikrt_file_ctime(ikptr filename, ikptr res){
|
||||||
return fix(0);
|
return fix(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue