FACT++  1.0
int dim_tcpip_init ( int  thr_flag)

Definition at line 235 of file tcpip.c.

References dim_get_write_timeout(), DIM_IO_path, dtq_create(), get_write_tmout(), init_done, io_sig_handler(), queue_id, tcpip_pipe_sig_handler(), Threads_on, and ushort.

Referenced by dim_tcpip_thread(), enable_sig(), tcpip_open_client(), and tcpip_open_server().

236 {
237 #ifdef WIN32
238  int addr, flags = 1;
239 /*
240  void tcpip_task();
241 */
242  void create_io_thread(void);
243 #else
244  struct sigaction sig_info;
245  sigset_t set;
246  void io_sig_handler();
247  void dummy_io_sig_handler();
248  void tcpip_pipe_sig_handler();
249 #endif
250  extern int get_write_tmout();
251 
252  if(init_done)
253  return(1);
254 
256 #ifdef WIN32
257  init_sock();
258  Threads_on = 1;
259 #else
260  if(thr_flag)
261  {
262  Threads_on = 1;
263  }
264  else
265  {
266  sigemptyset(&set);
267 
268  sigaddset(&set,SIGALRM);
269  sig_info.sa_handler = io_sig_handler;
270  sig_info.sa_mask = set;
271 #ifndef LYNXOS
272  sig_info.sa_flags = SA_RESTART;
273 #else
274  sig_info.sa_flags = 0;
275 #endif
276 
277  if( sigaction(SIGIO, &sig_info, 0) < 0 )
278  {
279  perror( "sigaction(SIGIO)" );
280  exit(1);
281  }
282 
283  sigemptyset(&set);
284  sig_info.sa_handler = tcpip_pipe_sig_handler;
285  sig_info.sa_mask = set;
286 #ifndef LYNXOS
287  sig_info.sa_flags = SA_RESTART;
288 #else
289  sig_info.sa_flags = 0;
290 #endif
291 
292  if( sigaction(SIGPIPE, &sig_info, 0) < 0 ) {
293  perror( "sigaction(SIGPIPE)" );
294  exit(1);
295  }
296 
297  }
298 #endif
299  if(Threads_on)
300  {
301 #ifdef WIN32
302  if(DIM_IO_path[0] == -1)
303  {
304  if( (DIM_IO_path[0] = (int)socket(AF_INET, SOCK_STREAM, 0)) == -1 )
305  {
306  perror("socket");
307  return(0);
308  }
309 
310  DIM_sockname.sin_family = PF_INET;
311  addr = 0;
312  DIM_sockname.sin_addr = *((struct in_addr *) &addr);
313  DIM_sockname.sin_port = htons((ushort) 2000);
314  ioctl(DIM_IO_path[0], FIONBIO, &flags);
315  }
316 #else
317  if(DIM_IO_path[0] == -1)
318  {
319  pipe(DIM_IO_path);
320  }
321 #endif
322  }
323  if(!queue_id)
324  queue_id = dtq_create();
325 
326 #ifdef WIN32
327 /*
328 #ifndef STDCALL
329  tid = _beginthread((void *)(void *)tcpip_task,0,NULL);
330 #else
331  tid = _beginthreadex(NULL, NULL,
332  tcpip_task,0,0,NULL);
333 #endif
334 */
335  create_io_thread();
336 #endif
337  init_done = 1;
338  return(1);
339 }
void io_sig_handler(int num)
Definition: tcpip.c:811
#define ushort
Definition: tcpip.c:88
int get_write_tmout()
Definition: utilities.c:298
int dtq_create()
Definition: dtq.c:353
static int DIM_IO_path[2]
Definition: tcpip.c:99
static int Threads_on
Definition: tcpip.c:90
static int init_done
Definition: tcpip.c:92
static int queue_id
Definition: tcpip.c:93
int dim_get_write_timeout()
Definition: tcpip.c:147
void tcpip_pipe_sig_handler(int num)
Definition: tcpip.c:677

+ Here is the call graph for this function:

+ Here is the caller graph for this function: