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:
Abdulaziz Ghuloum 2008-04-11 07:01:27 -04:00
parent 25344fa1d0
commit bdd81e2b05
4 changed files with 54 additions and 8 deletions

View File

@ -23,6 +23,8 @@
(lambda ()
(let f ()
(let-values ([(op ip) (accept-connection s)])
(printf "Connection from address ~a\n"
op)
(let ([op (transcoded-port op (native-transcoder))]
[ip (transcoded-port ip (native-transcoder))])
(display "What's your name? " op)

View File

@ -1206,7 +1206,10 @@
#| 20 |# "invalid file name"
#| 21 |# "non-blocking operation would block"
#| 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)
(let ([err (fxnot err)])
@ -2136,7 +2139,6 @@
(define out-queue '())
(define in-queue '())
(define (process-events)
(if (null? out-queue)
(if (null? in-queue)
@ -2241,12 +2243,22 @@
(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)
(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
(die who "server is closed" s))
(let ([sock (foreign-call "ikrt_accept" fd)])
(let ([sock (foreign-call "ikrt_accept" fd bv)])
(cond
[(eq? sock EAGAIN-error-code)
(call/cc
@ -2254,8 +2266,10 @@
(add-io-event fd k 'r)
(process-events)))
(do-accept-connection s who blocking?)]
[(< sock 0)
(io-error who s sock)]
[else
(socket->ports sock who #f blocking?)]))))
(socket->ports sock who (make-socket-info bv) blocking?)]))))
(define (accept-connection s)
(do-accept-connection s 'accept-connection #t))

View File

@ -1 +1 @@
1444
1445

View File

@ -59,6 +59,8 @@ ikrt_io_error(){
case EAGAIN : return fix(-22); /* hardcoded in ikarus.io.ss */
case EPIPE : return fix(-23);
case ECONNREFUSED : return fix(-24);
case ENOTSOCK : return fix(-25);
case ENOBUFS : return fix(-26);
}
return fix(-1);
}
@ -251,12 +253,37 @@ ikrt_listen(ikptr port, ikpcb* pcb){
return fix(sock);
}
#if 0
not used
ikptr
ikrt_getsockname(ikptr s, ikpcb* pcb){
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, ikpcb* pcb){
int sock = accept(unfix(s), NULL, NULL);
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){
return ikrt_io_error();
}
ref(bv, off_bytevector_length) = fix(addrlen);
return fix(sock);
}
@ -287,3 +314,6 @@ ikrt_file_ctime(ikptr filename, ikptr res){
return fix(0);
}