/[guile]/guile/guile-core/doc/ref/posix.texi
ViewVC logotype

Diff of /guile/guile-core/doc/ref/posix.texi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.2.7 by ossau, Fri Mar 29 20:11:13 2002 UTC revision 1.1.2.8 by ossau, Thu Aug 8 22:05:39 2002 UTC
# Line 735  Close the directory stream @var{stream}. Line 735  Close the directory stream @var{stream}.
735  The return value is unspecified.  The return value is unspecified.
736  @end deffn  @end deffn
737    
738    Here is an example showing how to display all the entries in a
739    directory:
740    
741    @lisp
742    (define dir (opendir "/usr/lib"))
743    (do ((entry (readdir dir) (readdir dir)))
744        ((eof-object? entry))
745      (display entry)(newline))
746    (closedir dir)
747    @end lisp
748    
749  @deffn {Scheme Procedure} sync  @deffn {Scheme Procedure} sync
750  @deffnx {C Function} scm_sync ()  @deffnx {C Function} scm_sync ()
751  Flush the operating system disk buffers.  Flush the operating system disk buffers.
# Line 791  Return the base name of the file name @v Line 802  Return the base name of the file name @v
802  base name is the file name without any directory components.  base name is the file name without any directory components.
803  If @var{suffix} is provided, and is equal to the end of  If @var{suffix} is provided, and is equal to the end of
804  @var{basename}, it is removed also.  @var{basename}, it is removed also.
805    
806    @lisp
807    (basename "/tmp/test.xml" ".xml")
808    @result{} "test"
809    @end lisp
810  @end deffn  @end deffn
811    
812    
# Line 1021  specifications introduced by a @code{%} Line 1037  specifications introduced by a @code{%}
1037  month and day names is dependent on the current locale.  The value returned  month and day names is dependent on the current locale.  The value returned
1038  is the formatted string.  is the formatted string.
1039  @xref{Formatting Date and Time, , , libc, The GNU C Library Reference Manual}.)  @xref{Formatting Date and Time, , , libc, The GNU C Library Reference Manual}.)
1040    
1041    @lisp
1042    (strftime "%c" (localtime (current-time)))
1043    @result{} "Mon Mar 11 20:17:43 2002"
1044    @end lisp
1045  @end deffn  @end deffn
1046    
1047  @deffn {Scheme Procedure} strptime format string  @deffn {Scheme Procedure} strptime format string
# Line 1654  be the value of @code{OPEN_READ} or @cod Line 1675  be the value of @code{OPEN_READ} or @cod
1675    
1676  @deffn {Scheme Procedure} open-input-pipe command  @deffn {Scheme Procedure} open-input-pipe command
1677  Equivalent to @code{open-pipe} with mode @code{OPEN_READ}.  Equivalent to @code{open-pipe} with mode @code{OPEN_READ}.
1678    
1679    @lisp
1680    (read-line (open-input-pipe "date"))
1681    @result{} "Mon Mar 11 20:10:44 GMT 2002"
1682    
1683    (waitpid WAIT_ANY)
1684    @result{} (24160 . 0)
1685    @end lisp
1686  @end deffn  @end deffn
1687    
1688  @deffn {Scheme Procedure} open-output-pipe command  @deffn {Scheme Procedure} open-output-pipe command
# Line 1677  close a pipe, but doesn't return the sta Line 1706  close a pipe, but doesn't return the sta
1706  * Network Address Conversion::  * Network Address Conversion::
1707  * Network Databases::  * Network Databases::
1708  * Network Sockets and Communication::  * Network Sockets and Communication::
1709    * Internet Socket Examples::
1710  @end menu  @end menu
1711    
1712  @node Network Address Conversion  @node Network Address Conversion
# Line 1818  found, an error will be thrown to one of Line 1848  found, an error will be thrown to one of
1848  @code{no-data}, corresponding to the equivalent @code{h_error} values.  @code{no-data}, corresponding to the equivalent @code{h_error} values.
1849  Unusual conditions may result in errors thrown to the  Unusual conditions may result in errors thrown to the
1850  @code{system-error} or @code{misc_error} keys.  @code{system-error} or @code{misc_error} keys.
1851    
1852    @lisp
1853    (gethost "www.gnu.org")
1854    @result{} #("www.gnu.org" () 2 4 (3353880842))
1855    
1856    (gethostbyname "www.emacs.org")
1857    @result{} #("emacs.org" ("www.emacs.org") 2 4 (1073448978))
1858    @end lisp
1859  @end deffn  @end deffn
1860    
1861  The following procedures may be used to step through the host  The following procedures may be used to step through the host
# Line 1991  database does not match this name, a sys Line 2029  database does not match this name, a sys
2029  The @code{getserv} procedure will take either a service name or number  The @code{getserv} procedure will take either a service name or number
2030  as its first argument; if given no arguments, it behaves like  as its first argument; if given no arguments, it behaves like
2031  @code{getservent} (see below).  @code{getservent} (see below).
2032    
2033    @lisp
2034    (getserv "imap" "tcp")
2035    @result{} #("imap2" ("imap") 143 "tcp")
2036    
2037    (getservbyport 88 "udp")
2038    @result{} #("kerberos" ("kerberos5" "krb5") 88 "udp")
2039    @end lisp
2040  @end deffn  @end deffn
2041    
2042  The following procedures may be used to step through the service  The following procedures may be used to step through the service
# Line 2381  These procedures are inconvenient to use Line 2427  These procedures are inconvenient to use
2427        (ntohl (uniform-vector-ref v 0)))))        (ntohl (uniform-vector-ref v 0)))))
2428  @end example  @end example
2429    
2430    
2431    @node Internet Socket Examples
2432    @subsection Network Socket Examples
2433    
2434    The following sections give examples of how to use network sockets.
2435    
2436    @menu
2437    * Internet Socket Client::
2438    * Internet Socket Server::
2439    @end menu
2440    
2441    
2442    @node Internet Socket Client
2443    @subsubsection Internet Socket Client Example
2444    
2445    @cindex socket client example
2446    The following example demonstrates an Internet socket client.
2447    It connects to the HTTP daemon running on the local machine and
2448    returns the contents of the root index URL.
2449    
2450    @example
2451    (let ((s (socket AF_INET SOCK_STREAM 0)))
2452      (connect s AF_INET (inet-aton "127.0.0.1") 80)
2453      (display "GET / HTTP/1.0\r\n\r\n" s)
2454    
2455      (do ((line (read-line s) (read-line s)))
2456          ((eof-object? line))
2457        (display line)
2458        (newline)))
2459    @end example
2460    
2461    
2462    @node Internet Socket Server
2463    @subsubsection Internet Socket Server Example
2464    
2465    @cindex socket server example
2466    The following example shows a simple Internet server which listens on
2467    port 2904 for incoming connections and sends a greeting back to the
2468    client.
2469    
2470    @example
2471    (let ((s (socket AF_INET SOCK_STREAM 0)))
2472      (setsockopt s SOL_SOCKET SO_REUSEADDR 1)
2473      ;; Specific address?
2474      ;; (bind s AF_INET (inet-aton "127.0.0.1") 2904)
2475      (bind s AF_INET INADDR_ANY 2904)
2476      (listen s 5)
2477    
2478      (simple-format #t "Listening for clients in pid: ~S" (getpid))
2479      (newline)
2480    
2481      (while #t
2482             (let* ((client-connection (accept s))
2483                    (client-details (cdr client-connection))
2484                    (client (car client-connection)))
2485               (simple-format #t "Got new client connection: ~S"
2486                              client-details)
2487               (newline)
2488               (simple-format #t "Client address: ~S"
2489                              (gethostbyaddr
2490                               (sockaddr:addr client-details)))
2491               (newline)
2492               ;; Send back the greeting to the client port
2493               (display "Hello client\r\n" client)
2494               (close client))))
2495    @end example
2496    
2497    
2498  @node System Identification  @node System Identification
2499  @section System Identification  @section System Identification
2500    

Legend:
Removed from v.1.1.2.7  
changed lines
  Added in v.1.1.2.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26