Index: src/System/Link/socket_link.cpp
===================================================================
--- src/System/Link/socket_link.cpp	(revision 2724)
+++ src/System/Link/socket_link.cpp	(working copy)
@@ -34,6 +34,13 @@
 
 hashset<pointer> socket_link_set;
 
+
+static void
+sn_callback (void *obj, void* info) {
+  socket_link_rep* con= (socket_link_rep*) obj;
+  if (con->alive) con->feed (LINK_OUT);
+}
+
 /******************************************************************************
 * Constructors and destructors for socket_links
 ******************************************************************************/
@@ -125,6 +132,10 @@
 #endif
     return "Error: non working connection to '" * where * "'";
   alive= true;
+
+  sn = socket_notifier (io, &sn_callback, this, NULL);
+  add_notifier (sn);
+  
   return "ok";
 #else
   return "Error: sockets not implemented";
@@ -242,6 +253,7 @@
   close (io);
   io= -1;
   alive= false;
+  remove_notifier (sn); sn = socket_notifier ();
   wait (NULL);
 #endif
 }
Index: src/System/Link/pipe_link.cpp
===================================================================
--- src/System/Link/pipe_link.cpp	(revision 2724)
+++ src/System/Link/pipe_link.cpp	(working copy)
@@ -31,6 +31,19 @@
 
 hashset<pointer> pipe_link_set;
 
+
+static void
+sn_callback_out (void *obj, void *info) {
+  pipe_link_rep* con= (pipe_link_rep*) obj;
+  if (con->alive) con->feed (LINK_OUT);
+}
+
+static void
+sn_callback_err (void *obj, void *info) {
+  pipe_link_rep* con= (pipe_link_rep*) obj;
+  if (con->alive) con->feed (LINK_ERR);
+}
+
 /******************************************************************************
 * Constructors and destructors for pipe_links
 ******************************************************************************/
@@ -124,6 +137,13 @@
 #endif
 
     alive= true;
+    
+    snout = socket_notifier (out, &sn_callback_out, this, NULL);
+    snerr = socket_notifier (err, &sn_callback_err, this, NULL);
+    
+    add_notifier (snout);
+    add_notifier (snerr);
+        
     if (/* !banner */ true) return "ok";
     else {
       int r;
@@ -214,6 +234,9 @@
     }
 #endif
     alive= false;
+    remove_notifier (snout); snout = socket_notifier ();
+    remove_notifier (snerr); snerr = socket_notifier ();
+
   }
   else {
     if (DEBUG_IO) cout << debug_io_string (string (tempout, r));
@@ -280,11 +303,16 @@
     killpg(pid,SIGKILL);
   }
   alive= false;
+  
+  
   close (in);
 #endif
   alive= false;
   wait (NULL);
 #endif
+
+  remove_notifier (snout); snout = socket_notifier ();
+  remove_notifier (snerr); snerr = socket_notifier ();
 }
 
 /******************************************************************************
Index: src/System/Link/socket_link.hpp
===================================================================
--- src/System/Link/socket_link.hpp	(revision 2724)
+++ src/System/Link/socket_link.hpp	(working copy)
@@ -12,6 +12,7 @@
 #ifndef SOCKET_LINK_H
 #define SOCKET_LINK_H
 #include "tm_link.hpp"
+#include "socket_notifier.hpp"
 
 /******************************************************************************
 * The socket_link class
@@ -24,6 +25,8 @@
   int    io;            // file descriptor for data going to the child
   string outbuf;        // pending output from plugin
 
+  socket_notifier sn;
+  
 public:
   socket_link_rep (string host, int port, int type, int fd);
   ~socket_link_rep ();
Index: src/System/Link/socket_server.cpp
===================================================================
--- src/System/Link/socket_server.cpp	(revision 2724)
+++ src/System/Link/socket_server.cpp	(working copy)
@@ -23,14 +23,21 @@
 #include <sys/wait.h>
 #endif
 
+
 hashset<pointer> socket_server_set;
 
+
+static void 
+sn_callback(void *obj, void *info) {
+  ((socket_server_rep*) obj)->start ();
+}
+
 /******************************************************************************
 * Constructors and destructors for socket_servers
 ******************************************************************************/
 
 socket_server_rep::socket_server_rep (int port2):
-  port (port2)
+ port (port2), sn ()
 {
   socket_server_set->insert ((pointer) this);
   server= -1;
@@ -84,6 +91,10 @@
     return "Error: call to 'listen' failed";
 
   alive= true;
+  
+  sn = socket_notifier (server, &sn_callback, this, NULL);
+  add_notifier (sn);
+  
   return "ok";
 #else
   return "Error: sockets not implemented";
@@ -142,6 +153,10 @@
   if (!alive) return;
   incoming= array<tm_link> ();
   alive= false;
+  
+  remove_notifier (sn);
+  sn = socket_notifier ();
+
   close (server);
   wait (NULL);
 #endif
Index: src/System/Link/pipe_link.hpp
===================================================================
--- src/System/Link/pipe_link.hpp	(revision 2724)
+++ src/System/Link/pipe_link.hpp	(working copy)
@@ -12,6 +12,7 @@
 #ifndef PIPE_LINK_H
 #define PIPE_LINK_H
 #include "tm_link.hpp"
+#include "socket_notifier.hpp"
 
 #ifdef OS_WIN32
 #include <sys/pipe.h>
@@ -50,6 +51,8 @@
   string outbuf;        // pending output from plugin
   string errbuf;        // pending errors from plugin
 
+  socket_notifier snout, snerr;
+  
 public:
   pipe_link_rep (string cmd);
   ~pipe_link_rep ();
Index: src/System/Link/socket_server.hpp
===================================================================
--- src/System/Link/socket_server.hpp	(revision 2724)
+++ src/System/Link/socket_server.hpp	(working copy)
@@ -12,6 +12,7 @@
 #ifndef SOCKET_SERVER_H
 #define SOCKET_SERVER_H
 #include "tm_link.hpp"
+#include "socket_notifier.hpp"
 
 /******************************************************************************
 * The socket_server class
@@ -22,6 +23,8 @@
   int server;               // listening socket descriptor
   array<tm_link> incoming;  // list of clients
 
+  socket_notifier sn;
+  
 public:
   socket_server_rep (int port);
   ~socket_server_rep ();
Index: src/System/Link/socket_notifier.cpp
===================================================================
--- src/System/Link/socket_notifier.cpp	(revision 0)
+++ src/System/Link/socket_notifier.cpp	(revision 0)
@@ -0,0 +1,78 @@
+
+/******************************************************************************
+* MODULE     : socket_notifier.cpp
+* DESCRIPTION: Notifiers for socket activity
+* COPYRIGHT  : (C) 2009 Massimiliano Gubinelli
+*******************************************************************************
+* This software falls under the GNU general public license version 3 or later.
+* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
+* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
+******************************************************************************/
+
+#ifndef __MINGW32__
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#endif
+#include <errno.h>
+#ifdef OS_WIN32
+#include <sys/misc.h>
+#endif
+
+#include "socket_notifier.hpp"
+#include "list.hpp"
+#include "iterator.hpp"
+
+list<socket_notifier> notifiers;
+
+void 
+add_notifier (socket_notifier sn) {
+  cout << "add notifier" << LF;
+  if (!is_nil(sn)) notifiers << sn;
+}
+
+void 
+remove_notifier (socket_notifier sn) {
+  cout << "remove notifier" << LF;
+  if (!is_nil(sn)) notifiers = remove (notifiers, sn);
+}
+
+void perform_select () {
+#ifndef __MINGW32__
+ // cout << "**********************************************" << LF;
+ // cout << "perform_select cycle" << LF;
+  while (true) {
+    fd_set rfds;
+    FD_ZERO (&rfds);
+    int max_fd= 0;
+    list<socket_notifier> it= notifiers;
+    while (! is_nil(it)) {
+      socket_notifier sn= it [0];
+      FD_SET (sn->fd, &rfds);
+      //cout << sn->fd << LF;
+      if (sn->fd >= max_fd) max_fd= sn->fd+1;
+      it = tail (it);
+    }
+    if (max_fd == 0) break;
+    
+    struct timeval tv;
+    tv.tv_sec  = 0;
+    tv.tv_usec = 0;
+    int nr= select (max_fd, &rfds, NULL, NULL, &tv);
+    if (nr==0) break;
+    
+    it= notifiers;
+    while (! is_nil(it)) {
+      socket_notifier sn=  it [0];
+      if (FD_ISSET (sn->fd, &rfds)) sn->notify ();
+      it = tail (it);
+    }
+  }
+#endif  
+}
+
+
Index: src/System/Link/socket_notifier.hpp
===================================================================
--- src/System/Link/socket_notifier.hpp	(revision 0)
+++ src/System/Link/socket_notifier.hpp	(revision 0)
@@ -0,0 +1,45 @@
+
+/******************************************************************************
+* MODULE     : socket_notifier.hpp
+* DESCRIPTION: Notifiers for socket activity
+* COPYRIGHT  : (C) 2009 Massimiliano Gubinelli
+*******************************************************************************
+* This software falls under the GNU general public license version 3 or later.
+* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
+* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
+******************************************************************************/
+
+#ifndef SOCKET_NOTIFIER_H
+#define SOCKET_NOTIFIER_H
+
+#include "basic.hpp"
+
+struct socket_notifier_rep : concrete_struct {
+  int fd; // file descriptor for the socket
+  void (*callback) (void*, void*); // callback
+  void *obj; // argument for callback
+  void *info; // additional info
+  
+public:
+  socket_notifier_rep (int _fd, void (*_callback) (void*, void*), void *_obj, void *_info)
+    : fd(_fd), callback(_callback), obj(_obj), info(_info) {} 
+  void notify () { if (callback) callback (obj, info); } 
+};
+
+
+class socket_notifier {
+  CONCRETE_NULL(socket_notifier);
+  inline socket_notifier (int _fd, void (*_callback) (void*, void*), void *_obj, void *_info = NULL) 
+    : rep (tm_new<socket_notifier_rep> (_fd, _callback, _obj, _info)) {}
+  friend bool operator==(socket_notifier sn1, socket_notifier sn2) {
+    return (sn1.rep == sn2.rep);
+  }
+};
+
+CONCRETE_NULL_CODE(socket_notifier);
+
+void add_notifier (socket_notifier sn); 
+void remove_notifier (socket_notifier sn);
+void perform_select ();
+
+#endif // SOCKET_NOTIFIER_H
Index: src/Texmacs/Server/tm_server.cpp
===================================================================
--- src/Texmacs/Server/tm_server.cpp	(revision 2724)
+++ src/Texmacs/Server/tm_server.cpp	(working copy)
@@ -19,6 +19,7 @@
 #include "socket_link.hpp"
 #include "socket_server.hpp"
 #include "dictionary.hpp"
+#include "socket_notifier.hpp"
 
 server* the_server= NULL;
 bool texmacs_started= false;
@@ -291,9 +292,13 @@
 
 void
 tm_server_rep::interpose_handler () {
+#if 0
   listen_to_servers ();
   listen_to_pipes ();
   listen_to_sockets ();
+#else
+  perform_select ();
+#endif
   listen_to_connections ();
   exec_pending_commands ();
 
Index: misc/admin/admin.makefile
===================================================================
--- misc/admin/admin.makefile	(revision 2724)
+++ misc/admin/admin.makefile	(working copy)
@@ -19,8 +19,8 @@
 tmdir = TeXmacs
 tmtgz = TeXmacs-1.0.7.2
 tmrpm = TeXmacs-1.0.7.2-1
-tmorig = /Users/vdhoeven/texmacs/src
-tmsrc = /Users/vdhoeven/texmacs/src/TeXmacs
+tmorig = /Users/Mgubi/t/nn/exp-notify
+tmsrc = /Users/Mgubi/t/nn/exp-notify/TeXmacs
 tmbin = ${exec_prefix}/libexec/TeXmacs
 tmdata = ${datarootdir}/TeXmacs
 so = dylib
