Added read-only clients, added stdin-close option to clients.
authorlbatlle@npdl268.bpo.hp.com
Fri, 21 Sep 2007 11:56:07 +0200
changeset 32 df110f784648
parent 31 c8d6b46dae2e
child 33 010af11f521e
Added read-only clients, added stdin-close option to clients.
app_control.c
handlers.h
main.c
main.h
server.c
unix_server.c
--- a/app_control.c	Fri Sep 21 09:27:10 2007 +0200
+++ b/app_control.c	Fri Sep 21 11:56:07 2007 +0200
@@ -84,10 +84,21 @@
     return 0;
 }
 
-void app_control_send_to_stdin(const char *buffer, size_t size)
+void app_control_local_send_to_stdin(const char *buffer, size_t size)
 {
     if (size == 0)
         close(app_stdin);
     else
         write(app_stdin, buffer, size);
 }
+
+void app_control_remote_send_to_stdin(const char *buffer, size_t size)
+{
+    if (command_line.s_param.client_can_write)
+    {
+        if (size == 0 && command_line.s_param.client_may_close_app_stdin)
+            close(app_stdin);
+        else
+            write(app_stdin, buffer, size);
+    }
+}
--- a/handlers.h	Fri Sep 21 09:27:10 2007 +0200
+++ b/handlers.h	Fri Sep 21 11:56:07 2007 +0200
@@ -15,7 +15,8 @@
 void app_control_shutdown();
 void app_control_prepare_read_fdset(fd_set *read_set, int *maxfd);
 int  app_control_process_read_fdset(fd_set *read_set);
-void app_control_send_to_stdin(const char *buffer, size_t size);
+void app_control_remote_send_to_stdin(const char *buffer, size_t size);
+void app_control_local_send_to_stdin(const char *buffer, size_t size);
 
 /* unix_client.c */
 void c_unix_connect_socket();
--- a/main.c	Fri Sep 21 09:27:10 2007 +0200
+++ b/main.c	Fri Sep 21 11:56:07 2007 +0200
@@ -49,6 +49,8 @@
     printf(" -t     Run the child as connected to a terminal (raw mode in "
         "client)\n");
     printf(" -n MAX Serve at most MAX sockets for each transport\n");
+    printf(" -w     The remote clients can write to the application.\n");
+    printf(" -x     The remote clients end will close app's stdin.\n");
     return 0;
 }
 
@@ -85,6 +87,7 @@
     command_line.s_param.send_xterm_resize = 1;
     command_line.s_param.client_may_close_app_stdin = 0;
     command_line.s_param.detach = 0;
+    command_line.s_param.client_can_write = 0;
 
     command_line.tcp_port = 40000; /* Arbitrary */
     command_line.buffer_size = 4096; /* Arbitrary */
@@ -103,7 +106,7 @@
     extern int optind, opterr, optopt;
 
     while(1) {
-        c = my_getopt(argc, argv, "tp:NrdPn:c:h");
+        c = my_getopt(argc, argv, "tp:NrdPn:c:hwx");
 
         if (c == -1)
             break;
@@ -136,6 +139,12 @@
                 showhelp(argv[0]);
                 exit(0);
                 break;
+            case 'w':
+                command_line.s_param.client_can_write = 1;
+                break;
+            case 'x':
+                command_line.s_param.client_may_close_app_stdin = 1;
+                break;
             case '?':
                 error("Wrong option %c.\n", optopt);
         }
--- a/main.h	Fri Sep 21 09:27:10 2007 +0200
+++ b/main.h	Fri Sep 21 11:56:07 2007 +0200
@@ -17,6 +17,7 @@
         char use_blocking_sockets;
         char send_xterm_resize;
         char client_may_close_app_stdin;
+        char client_can_write;
         int detach; /* detach from terminal as nohup */
         char **command; /* ordono por exec */
     } s_param;
--- a/server.c	Fri Sep 21 09:27:10 2007 +0200
+++ b/server.c	Fri Sep 21 11:56:07 2007 +0200
@@ -45,14 +45,10 @@
         if (FD_ISSET(0, &read_set))
         {
             res = read(0, stream_buffer, stream_buffer_size);
+            /* if res is 0, the fcall will close app_stdin */
+            app_control_local_send_to_stdin(stream_buffer, res);
             if (res == 0)
-            {
-                app_control_send_to_stdin(stream_buffer, 0);
                 stdin_opened = 0;
-            } else
-            {
-                app_control_send_to_stdin(stream_buffer, res);
-            }
         }
 
         s_unix_process_read_fdset(&read_set);
--- a/unix_server.c	Fri Sep 21 09:27:10 2007 +0200
+++ b/unix_server.c	Fri Sep 21 11:56:07 2007 +0200
@@ -179,7 +179,7 @@
                 remove_conn_socket(i);
             } else
             {
-                app_control_send_to_stdin(stream_buffer, res);
+                app_control_remote_send_to_stdin(stream_buffer, res);
             }
         }
     }