FACT++  1.0
int tcpip_write_nowait ( int  conn_id,
char *  buffer,
int  size 
)

Definition at line 1435 of file tcpip.c.

References NET_CONNECTION::channel, DIM_ERROR, DIMTCPWRRTY, dna_report_error(), Net_conns, set_blocking(), set_non_blocking(), size, tcpip_would_block(), NET_CONNECTION::write_timedout, Write_timeout, and writesock.

Referenced by dna_write_bytes().

1436 {
1437  /* Do a (asynchronous) write to conn_id.
1438  */
1439  int wrote, ret, selret;
1440  int tcpip_would_block();
1441 #ifdef __linux__
1442  struct pollfd pollitem;
1443 #else
1444  struct timeval timeout;
1445  fd_set wfds;
1446 #endif
1447 
1448  set_non_blocking(Net_conns[conn_id].channel);
1449 /*
1450 #ifdef __linux__
1451  tcpip_get_send_space(conn_id);
1452 #endif
1453 */
1454  wrote = (int)writesock( Net_conns[conn_id].channel, buffer, (size_t)size, 0 );
1455 #ifndef WIN32
1456  ret = errno;
1457 #else
1458  ret = WSAGetLastError();
1459 #endif
1460 /*
1461  if((wrote == -1) && (!tcpip_would_block(ret)))
1462  {
1463  dna_report_error(conn_id, 0,
1464  "Writing (non-blocking) to", DIM_ERROR, DIMTCPWRRTY);
1465 printf("Writing %d, ret = %d\n", size, ret);
1466  }
1467 */
1468  set_blocking(Net_conns[conn_id].channel);
1469  if(wrote == -1)
1470  {
1471  if(tcpip_would_block(ret))
1472  {
1473 #ifdef __linux__
1474  pollitem.fd = Net_conns[conn_id].channel;
1475  pollitem.events = POLLOUT;
1476  pollitem.revents = 0;
1477  selret = poll(&pollitem, 1, Write_timeout*1000);
1478 #else
1479  timeout.tv_sec = Write_timeout;
1480  timeout.tv_usec = 0;
1481  FD_ZERO(&wfds);
1482  FD_SET( Net_conns[conn_id].channel, &wfds);
1483  selret = select(FD_SETSIZE, NULL, &wfds, NULL, &timeout);
1484 #endif
1485  if(selret > 0)
1486  {
1487  wrote = (int)writesock( Net_conns[conn_id].channel, buffer, (size_t)size, 0 );
1488  if( wrote == -1 )
1489  {
1490  dna_report_error(conn_id, 0,
1491  "Writing to", DIM_ERROR, DIMTCPWRRTY);
1492  return(0);
1493  }
1494  }
1495  }
1496  else
1497  {
1498  dna_report_error(conn_id, 0,
1499  "Writing (non-blocking) to", DIM_ERROR, DIMTCPWRRTY);
1500  return(0);
1501  }
1502  }
1503  if(wrote == -1)
1504  {
1505  Net_conns[conn_id].write_timedout = 1;
1506  }
1507  return(wrote);
1508 }
#define DIMTCPWRRTY
Definition: dim_common.h:294
DllExp DIM_NOSHARE NET_CONNECTION * Net_conns
Definition: conn_handler.c:32
int tcpip_would_block(int code)
Definition: tcpip.c:1545
int channel
Definition: dim.h:398
int set_blocking(int channel)
Definition: tcpip.c:1421
#define writesock(a, b, c, d)
Definition: tcpip.c:42
void dna_report_error(int conn_id, int code, char *routine_name, int severity, int errcode)
Definition: dna.c:903
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
int size
Definition: db_dim_server.c:17
static int Write_timeout
Definition: tcpip.c:105
int write_timedout
Definition: dim.h:412
int set_non_blocking(int channel)
Definition: tcpip.c:1407

+ Here is the call graph for this function:

+ Here is the caller graph for this function: