gcl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gcl-devel] Re: Server sockets with GCL?


From: Camm Maguire
Subject: Re: [Gcl-devel] Re: Server sockets with GCL?
Date: 07 May 2004 11:51:03 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Greetings!

<address@hidden> writes:

> >Greetings!
> >
> >A few observations regarding sockets in GCL:
> (a lot of interesting and useful stuff snipped)
> It is now clear to me that the level of familiarity with GCL's history
> and the physical source file dependencies required to make these changes
> is well above my current expertise.  Although I might be able to make the
> code work for my platform and distro, I don't have the means to test that
> I haven't broken one or more implementations on other platforms, nor to
> generalize the build and configuration process.
> Regarding the issues of fork() and threads, yes, I would expect a general
> implementation of threads to be necessary to make server sockets as useful
> as in other languages (or maybe as in other Lisp implementations, as you
> note).  
> However, in the particular situation I face at the moment, my "server" need
> not be able to (and in fact, cannot currently) serve multiple concurrent
> clients.  Thus, I would be using the server socket only with one client at
> a time.  
> My main need for now is a function to listen "passively" and produce
> the same sort of thing produced by SI::SOCKET.  I'm not particular whether
> the form I employ is a keyword-based option on SI::SOCKET or another function
> like ACCEPT-SOCKET-CONNECTION altogether.
> Tom Johnson

OK, for this 'quick and dirty':

1) Apply the patch below
2) In GCL: (defun foo (x) x) (setq s (si::socket 1919 :server 'foo))
      (setq q (si::accept s))
3) In some other window, either netcat or telnet localhost 1919
4) IN GCL: accept should return with a cons containing a two way
   stream
5) In other window, type hello
6) In GCL: (read-line (car q)) ; should give "hello"
7) In GCL: (format (car q) "there~%")
8) there should appear in other window.

Not quite ready to commit this as the dummy server function is pretty
ugly.  I think the original intent might have been to define handlers
via the SIGIO-INTERRUPT symbol and the SET-SIGIO-FOR-FD function.

Do we want to specify a server function in this case, and if so, what
do we want it to do and when?

Take care,

=============================================================================
Index: o/file.d
===================================================================
RCS file: /cvsroot/gcl/gcl/o/file.d,v
retrieving revision 1.21.4.1.2.7
diff -u -r1.21.4.1.2.7 file.d
--- o/file.d    3 May 2004 21:35:58 -0000       1.21.4.1.2.7
+++ o/file.d    7 May 2004 15:40:40 -0000
@@ -38,6 +38,13 @@
 #define IN_FILE
 #include "include.h"
 
+#ifdef HAVE_NSOCKET
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#endif
+
 #ifdef HAVE_READLINE
 #define kclgetc(FP)            rl_getc_em(FP)
 #define kclungetc(C, FP)       rl_ungetc_em(C, FP)
@@ -2302,6 +2309,36 @@
    
 @)
 
+@(static defun accept (strm)
+int fd,n;
+struct sockaddr_in addr;
+@
+
+  if (type_of(strm)!=t_stream)
+     FEwrong_type_argument(sLstream,strm);
+  if (strm->sm.sm_mode!=smm_two_way)
+     FEerror("~S is not a two way stream",1,strm);
+  strm=STREAM_INPUT_STREAM(strm);
+  if (type_of(strm)!=t_stream)
+     FEwrong_type_argument(sLstream,strm);
+  if (strm->sm.sm_mode!=smm_socket)
+     FEerror("~S is not a socket stream",1,strm);
+  fd=SOCKET_STREAM_FD(strm);
+  n=sizeof(addr);
+  fd=accept(fd,(struct sockaddr *)&addr, &n);
+  if (fd < 0) {
+     perror("ERROR ! accept on socket failed in sock_accept_connection");
+     fflush(stderr);
+     @(return `Cnil`);
+  }
+  strm = make_two_way_stream
+       (make_socket_stream(fd,gcl_sm_input,Cnil,Cnil,Cnil,Cnil),
+       make_socket_stream(fd,gcl_sm_output,Cnil,Cnil,Cnil,Cnil));
+  strm=make_cons(strm,make_simple_string(inet_ntoa(addr.sin_addr)));
+  @(return `strm`);
+
+@)
+
 DEF_ORDINARY("MYADDR",sKmyaddr,KEYWORD,"");
 DEF_ORDINARY("MYPORT",sKmyport,KEYWORD,"");
 DEF_ORDINARY("ASYNC",sKasync,KEYWORD,"");
@@ -2441,6 +2478,7 @@
        make_si_function("FREAD",Lfread);
 #ifdef HAVE_NSOCKET
        make_si_function("SOCKET",Lsocket);
+       make_si_function("ACCEPT",Laccept);
 #endif
        make_function("STREAMP", Lstreamp);
        make_function("INPUT-STREAM-P", Linput_stream_p);
@@ -2476,8 +2514,8 @@
 char *str;
 {
        object faslfile, data;
-#ifdef UNIX
-#ifdef BSD
+#ifndef SEEK_TO_END_OFILE
+#if defined(UNIX) && defined(BSD)
        FILE *fp;
        int i;
 #ifdef HAVE_AOUT
Index: o/read.d
===================================================================
RCS file: /cvsroot/gcl/gcl/o/read.d,v
retrieving revision 1.14.4.1.2.2.2.4
diff -u -r1.14.4.1.2.2.2.4 read.d
--- o/read.d    6 Nov 2003 16:16:53 -0000       1.14.4.1.2.2.2.4
+++ o/read.d    7 May 2004 15:41:02 -0000
@@ -2095,9 +2095,9 @@
                token->st.st_self[i++] = char_code(c);
        }
  FINISH:
-#ifdef DOES_CRLF
+/*#ifdef DOES_CRLF*/
        if (i > 0 && token->st.st_self[i-1] == '\r') i--;
-#endif
+/*#endif*/
        token->st.st_fillp = i;
   /* no disadvantage to returning an adjustable string */
   
=============================================================================


> _______________________________________________
> Gcl-devel mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/gcl-devel

-- 
Camm Maguire                                            address@hidden
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah




reply via email to

[Prev in Thread] Current Thread [Next in Thread]