This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ppp/tests/windows_telnet.c fixes


More well behaved demo app.


-- 
Øyvind Harboe
http://www.zylin.com

Index: current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/ppp/current/ChangeLog,v
retrieving revision 1.6
diff -w -u -r1.6 ChangeLog
--- current/ChangeLog	23 Jul 2004 11:00:40 -0000	1.6
+++ current/ChangeLog	19 Aug 2004 20:08:38 -0000
@@ -1,3 +1,14 @@
+2004-08-19  Oyvind Harboe <oyvind.harboe@zylin.com>
+	* windows_telnet.c: 
+
+	* now demonstrates chat script TIMEOUT, which makes
+	connection more snappy.
+
+	* repeats attempts at connect until a connection
+	is established instead of a single try.
+
+	* after a telnet session is aborted, a new one can be established.
+
 2004-06-29	Matt Jerdonek <maj1224@yahoo.com>
 
 	* cdl/ppp.cdl:
Index: current/tests/windows_telnet.c
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/ppp/current/tests/windows_telnet.c,v
retrieving revision 1.1
diff -w -u -r1.1 windows_telnet.c
--- current/tests/windows_telnet.c	23 Jul 2004 11:00:41 -0000	1.1
+++ current/tests/windows_telnet.c	19 Aug 2004 20:08:38 -0000
@@ -70,6 +70,7 @@
 
 static char *windows_script[] =
 {
+	"TIMEOUT",		"2",
       "",       		"CLIENTCLIENT\\c",
       "CLIENTSERVER",	"\\c",
     0
@@ -91,6 +92,9 @@
 		sin.sin_addr.s_addr = INADDR_ANY;
 		sin.sin_port = htons(23);
 
+		unsigned int opt = 1;
+		if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))!=-1) 
+		{
 		/* bind the socket to the port number */
 		if (bind(sd, (struct sockaddr *) &sin, sizeof(sin)) != -1) 
 		{
@@ -104,26 +108,51 @@
 				{
 					for (;;)
 					{
+						  char *PROMPT="eCos>";
+							if (write(sd_current, PROMPT, strlen(PROMPT)) != 
+							(int)strlen(PROMPT)) 
+							{
+								goto AbortSession;
+							}
 						/* get a message from the client */
-						
-						char t[256];
+							char dir[256];
 						int len;
-						len=recv(sd_current, t, sizeof(t)-1, 0);
-						if (len == -1) 
+							size_t i;
+							for (i=0; i<sizeof(dir)-1; i++)
 						{
-							break;
+								// returns when a full line has been collected
+								len=read(sd_current, dir+i, 1);
+								if (len != 1) 
+								{
+									goto AbortSession;
+								} else
+								{
+									if (write(sd_current, dir+i, 1)!=1)
+									{
+										goto AbortSession;
+									}
+									
+									// ignore
+									if (dir[i]=='\r')
+									{
+										i--;
 						}
 
-						if (send(sd_current, t, len, 0)!=len)
+									if (dir[i]=='\n')
 						  {
 						    break;
 						  }
 					}
+							}
+							dir[i]=0;
+						}
+					AbortSession:
 		    	    /* close up both sockets */
 					close(sd_current); 
 				}
 			}
 		}
+		}
 		close(sd);
 	}
 }	
@@ -131,18 +160,21 @@
 
 int main(int argc, char **argv)
 {
-    cyg_ppp_options_t options;
-    cyg_ppp_handle_t ppp_handle;
-
     // Bring up the TCP/IP network
     init_all_network_interfaces();
 
+  for (;;)
+    {
+        cyg_ppp_options_t options;
+        cyg_ppp_handle_t ppp_handle;
+
     // Initialize the options
     cyg_ppp_options_init( &options );
 
 	options.script=windows_script;
     options.baud = CYGNUM_SERIAL_BAUD_38400;
 	options.flowctl = CYG_PPP_FLOWCTL_NONE;
+	options.idle_time_limit = 0; // never shut down.    	
 	
     // Start up PPP
     ppp_handle = cyg_ppp_up( "/dev/ser0", &options );
@@ -165,3 +197,4 @@
         cyg_ppp_wait_down( ppp_handle );
     }
 }
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]