Changeset 27293 in project


Ignore:
Timestamp:
08/24/12 16:42:35 (9 years ago)
Author:
felix winkelmann
Message:

unix-sockets 1.7: added unix-pair, contributed by zb centuries ago

Location:
release/4/unix-sockets
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • release/4/unix-sockets/tags/1.7/unix-sockets.scm

    r24851 r27293  
    4343   unix-close
    4444   unix-listener?
    45    unix-listen)
     45   unix-listen
     46   unix-pair)
    4647
    4748;; TODO: errno should be accessed using the proper API?
     
    127128  return s2;
    128129}
     130
     131static int
     132create_socket_pair(___out int *s2)
     133{
     134  int s1, rc;
     135  int pair[2];
     136  rc = socketpair(PF_LOCAL, SOCK_STREAM, 0, pair);
     137  if (rc < 0) return -1;
     138  s1 = pair[0];
     139  *s2 = pair[1];
     140  return s1;
     141}
     142
    129143<#
    130144
     
    152166        (unix-error 'unix-connect "can not connect" filename)
    153167        (io-ports 'unix-connect n) ) ) )
     168
     169(define (unix-pair)
     170  (let-values (((s1 s2) (create_socket_pair)))
     171    (if (negative? s1)
     172        (unix-error 'unix-pair "cannot create socket pair")
     173        (let-values (((i1 o1) (io-ports 'unix-pair s1))
     174                     ((i2 o2) (io-ports 'unix-pair s2)))
     175          (values i1 o1 i2 o2)))))
    154176
    155177(define-constant +buffer-size+ 1024)
  • release/4/unix-sockets/tags/1.7/unix-sockets.setup

    r24851 r27293  
    88 'unix-sockets
    99 '("unix-sockets.so" "unix-sockets.import.so")
    10  '((version 1.6)))
     10 '((version 1.7)))
  • release/4/unix-sockets/trunk/unix-sockets.scm

    r24851 r27293  
    4343   unix-close
    4444   unix-listener?
    45    unix-listen)
     45   unix-listen
     46   unix-pair)
    4647
    4748;; TODO: errno should be accessed using the proper API?
     
    127128  return s2;
    128129}
     130
     131static int
     132create_socket_pair(___out int *s2)
     133{
     134  int s1, rc;
     135  int pair[2];
     136  rc = socketpair(PF_LOCAL, SOCK_STREAM, 0, pair);
     137  if (rc < 0) return -1;
     138  s1 = pair[0];
     139  *s2 = pair[1];
     140  return s1;
     141}
     142
    129143<#
    130144
     
    152166        (unix-error 'unix-connect "can not connect" filename)
    153167        (io-ports 'unix-connect n) ) ) )
     168
     169(define (unix-pair)
     170  (let-values (((s1 s2) (create_socket_pair)))
     171    (if (negative? s1)
     172        (unix-error 'unix-pair "cannot create socket pair")
     173        (let-values (((i1 o1) (io-ports 'unix-pair s1))
     174                     ((i2 o2) (io-ports 'unix-pair s2)))
     175          (values i1 o1 i2 o2)))))
    154176
    155177(define-constant +buffer-size+ 1024)
  • release/4/unix-sockets/trunk/unix-sockets.setup

    r24851 r27293  
    88 'unix-sockets
    99 '("unix-sockets.so" "unix-sockets.import.so")
    10  '((version 1.6)))
     10 '((version 1.7)))
Note: See TracChangeset for help on using the changeset viewer.