~ubuntu-branches/ubuntu/quantal/texmacs/quantal

« back to all changes in this revision

Viewing changes to src/System/Link/socket_server.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Atsuhito KOHDA
  • Date: 2010-04-23 07:09:40 UTC
  • mfrom: (4.1.8 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100423070940-72mjdmdepfgrvo8f
Tags: 1:1.0.7.4-2
Re-upload, former upload failed with wrong diff.gz perhaps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <sys/wait.h>
24
24
#endif
25
25
 
26
 
 
27
26
hashset<pointer> socket_server_set;
28
 
 
29
 
 
30
 
static void 
31
 
socket_server_callback(void *obj, void *info) {
32
 
  socket_server_rep* ss = (socket_server_rep*) obj;
33
 
  ss->start_client ();
34
 
}
 
27
void socket_server_callback (void *obj, void *info);
35
28
 
36
29
/******************************************************************************
37
30
* Constructors and destructors for socket_servers
60
53
  return N (socket_server_set);
61
54
}
62
55
 
 
56
void
 
57
close_all_servers () {
 
58
#ifndef __MINGW32__
 
59
  iterator<pointer> it= iterate (socket_server_set);
 
60
  while (it->busy()) {
 
61
    socket_server_rep* ss= (socket_server_rep*) it->next();
 
62
    if (ss->alive) {
 
63
      // FIXME: cleanly close the connection to the socket here
 
64
      ss->alive= false;
 
65
    }
 
66
  }
 
67
#endif
 
68
}
 
69
 
63
70
/******************************************************************************
64
71
* Routines for socket_servers
65
72
******************************************************************************/
119
126
    incoming= update;
120
127
    incoming << make_socket_link (addr, -1, SOCKET_SERVER, client);
121
128
  }
122
 
  
123
 
  if (!is_nil (feed_cmd)) feed_cmd->apply (); // call the data processor
124
129
#endif
125
130
}
126
131
 
164
169
}
165
170
 
166
171
/******************************************************************************
167
 
* Listen to all active servers (may be optimized for speed)
 
172
* Call back for new information on server
168
173
******************************************************************************/
169
174
 
170
 
void
171
 
listen_to_servers () {
 
175
void 
 
176
socket_server_callback (void *obj, void *info) {
172
177
#ifndef __MINGW32__
173
 
  while (true) {
174
 
    fd_set fds;
175
 
    FD_ZERO (&fds);
176
 
    int max_fd= 0;
177
 
    iterator<pointer> it= iterate (socket_server_set);
178
 
    while (it->busy()) {
179
 
      socket_server_rep* con= (socket_server_rep*) it->next();
180
 
      if (con->alive) {
181
 
        FD_SET (con->server, &fds);
182
 
        if (con->server >= max_fd) max_fd= con->server+1;
183
 
      }
184
 
    }
185
 
    if (max_fd == 0) break;
186
 
 
 
178
  (void) info;
 
179
  socket_server_rep* ss = (socket_server_rep*) obj;
 
180
  bool busy= true;
 
181
  bool news= false;
 
182
  while (busy) {
 
183
    fd_set rfds;
 
184
    FD_ZERO (&rfds);
 
185
    int max_fd= ss->server + 1;
 
186
    FD_SET (ss->server, &rfds);
 
187
  
187
188
    struct timeval tv;
188
189
    tv.tv_sec  = 0;
189
190
    tv.tv_usec = 0;
190
 
    int nr= select (max_fd, &fds, NULL, NULL, &tv);
191
 
    ASSERT (nr != -1, "call to 'select' failed");
192
 
    if (nr == 0) return;
 
191
    select (max_fd, &rfds, NULL, NULL, &tv);
193
192
 
194
 
    it= iterate (socket_server_set);
195
 
    while (it->busy()) {
196
 
      socket_server_rep* con= (socket_server_rep*) it->next();
197
 
      if (con->alive && FD_ISSET (con->server, &fds)) con->start_client ();
 
193
    busy= false;
 
194
    if (ss->alive && FD_ISSET (ss->server, &rfds)) {
 
195
      //cout << "server_callback" << LF;
 
196
      ss->start_client ();
 
197
      busy= news= true;
198
198
    }
199
199
  }
 
200
  
 
201
  if (!is_nil (ss->feed_cmd) && news)
 
202
    ss->feed_cmd->apply (); // call the data processor
200
203
#endif
201
204
}