128 INTS4 retval, buflen_tmp;
132 struct timeval read_timeout;
133 fd_set xrmask, xwmask, xemask;
134 INTS4 num_of_bytes_read = 0;
136 buflen_tmp = i_buflen;
137 p_buffer_tmp = p_buffer;
142 FD_SET(i_channel, &xrmask);
143 read_timeout.tv_sec = i_timeout;
144 read_timeout.tv_usec = 0;
146 printf(
"STC: read %6d bytes channel %d ", i_buflen, i_channel);
149 while (num_of_bytes_read < i_buflen && buflen_tmp > 0) {
150 if (i_timeout >= 0) {
161 retval = select(i_channel + 1, &xrmask, &xwmask, &xemask, &read_timeout);
175 sprintf(
c_msg,
"STC select error channel %d", i_channel);
191 retval = recv(i_channel, p_buffer_tmp, buflen_tmp, 0);
193 retval = read(i_channel, p_buffer_tmp, buflen_tmp);
208 sprintf(
c_msg,
"STC read error channel %d", i_channel);
220 num_of_bytes_read += retval;
221 buflen_tmp -= retval;
222 p_buffer_tmp += retval;
223 if (i_retry == 100000) {
224 printf(
"Request %d bytes, read %d, timeout after 100000 retries\n", i_buflen, num_of_bytes_read);
229 read_timeout.tv_sec = 100;
230 read_timeout.tv_usec = 0;
238 if (num_of_bytes_read == i_buflen) {
335 printf(
"STC: write %5d bytes channel %d ", i_buflen, i_channel);
338 l_retval = send(i_channel, p_buffer, i_buflen, 0);
350 sprintf(
c_msg,
"STC write error channel %d", i_channel);
365 if (l_retval == i_buflen) {
495 memset(&s_client, 0,
sizeof(s_client));
502 WORD wVersionRequested;
505 wVersionRequested = MAKEWORD(2, 2);
507 if (WSAStartup(wVersionRequested, &wsaData) != 0) {
508 printf(
"WinSock NOT found");
513 if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
517 printf(
"WinSock %d.%d", LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));
523 s_client.
socket =
socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
525 *ps_client = s_client;
526 *pi_channel = s_client.
socket;
528 switch (s_client.
socket) {
533 case ESOCKTNOSUPPORT:
535 case EPROTONOSUPPORT:
546 if ((s_client.
hostentptr = gethostbyname(c_node)) == NULL) {
549 closesocket(s_client.
socket);
559 s_client.sock.sin_family = s_client.
hostentstruct.h_addrtype;
560 s_client.sock.sin_port = htons(l_port);
561 s_client.sock.sin_addr = *((
struct in_addr*)s_client.
hostentstruct.h_addr);
563 retval = connect(s_client.
socket, (
struct sockaddr*)&s_client.sock,
sizeof(s_client.sock));
566 closesocket(s_client.
socket);
591 *ps_client = s_client;
693 accept(ps_server->sock_rw, (
struct sockaddr*)&ps_server->sock_name, (socklen_t*)&ps_server->namelength);
695 *pi_channel = accept(ps_server->sock_rw, (
struct sockaddr*)&ps_server->sock_name, (uint*)&ps_server->namelength);
697 if (*pi_channel == -1) {
851 INTS4 retval, retry, on;
854 memset(&s_server, 0,
sizeof(s_server));
857 WORD wVersionRequested;
860 wVersionRequested = MAKEWORD(2, 2);
862 if (WSAStartup(wVersionRequested, &wsaData) != 0) {
863 printf(
"WinSock NOT found");
868 if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
872 printf(
"WinSock %d.%d", LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));
887 s_server.
sock_rw =
socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
894 case ESOCKTNOSUPPORT:
896 case EPROTONOSUPPORT:
909 printf(
"--E--f_stc_createserver() error get local hostname\n");
914 printf(
"--E--f_stc_createserver() error get local Internet address\n");
920 s_server.
sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
921 s_server.
sock_name.sin_port = htons(*pl_port);
925 if (retval == -1 && retry == 0) {
947 while (retval == -1 && retry == 1) {
949 s_server.
sock_rw =
socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
956 case ESOCKTNOSUPPORT:
958 case EPROTONOSUPPORT:
971 printf(
"--E--f_stc_createserver() error get local hostname\n");
976 printf(
"--E--f_stc_createserver() error get local Internet address\n");
984 s_server.
sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
985 s_server.
sock_name.sin_port = htons(*pl_port);
993 if (*pl_port > 65535) {
994 printf(
"--E--f_stc_createserver() portnumber exceeded > 655535\n");
1016 retval = listen(s_server.
sock_rw, 5);
1030 *ps_server = s_server;
1099 if (ps_tcp->socket) {
1100 retval = shutdown(ps_tcp->socket, 2);
1104 retval = close(ps_tcp->socket);
1180 retval = close(i_channel);
1259 struct timeval read_timeout;
1260 fd_set rset, allset, wset, eset;
1261 INTS4 listenfd, maxfd, sts;
1263 read_timeout.tv_sec = 0;
1264 read_timeout.tv_usec = 0;
1266 listenfd = ps_server->
sock_rw;
1272 FD_SET(listenfd, &rset);
1273 FD_SET(listenfd, &wset);
1274 FD_SET(listenfd, &eset);
1277 sts = select(maxfd + 1, &rset, &wset, &eset, &read_timeout);
1294 if (FD_ISSET(listenfd, &eset)) {
1298 if (FD_ISSET(listenfd, &rset)) {
1302 if (FD_ISSET(listenfd, &wset)) {
1410 sprintf(c_line,
"-I- f_stc failure");
1413 sprintf(c_line,
"-I- f_stc failure");
1416 sprintf(c_line,
"-I- f_stc invalid socket number");
1419 sprintf(c_line,
"-I- f_stc buffer points outside allocated address space");
1422 sprintf(c_line,
"-I- f_stc buffer length is negative");
1425 sprintf(c_line,
"-I- f_stc time limit is negativ or to long");
1428 sprintf(c_line,
"-I- f_stc timeout read data from socket");
1431 sprintf(c_line,
"-I- f_stc socket number points to a file not a socket");
1434 sprintf(c_line,
"-I- f_stc invalid address specified in parameter");
1437 sprintf(c_line,
"-I- f_stc the specified address family is not supported");
1440 sprintf(c_line,
"-I- f_stc The specified socket type is not supported.");
1443 sprintf(c_line,
"-I- f_stc The specified protocol is not supported.");
1446 sprintf(c_line,
"-I- f_stc The per-process descriptor table is full.");
1449 sprintf(c_line,
"-I- f_stc No buffer space is available. The socket can't be created");
1452 sprintf(c_line,
"-I- f_stc socket is already connected.");
1455 sprintf(c_line,
"-I- f_stc connection timed out without establishing a connection.");
1458 sprintf(c_line,
"-I- f_stc The network is not reachable from this host.");
1461 sprintf(c_line,
"-I- f_stc The specified Internet Address and port is already in use.");
1464 sprintf(c_line,
"-I- f_stc socket address is protected.");
1467 sprintf(c_line,
"-I- f_stc connection refused.");
1470 sprintf(c_line,
"-I- f_stc error connect portserver");
1473 sprintf(c_line,
"-I- f_stc error register service at portserver");
1476 sprintf(c_line,
"-I- f_stc error write buffer to portserver");
1479 sprintf(c_line,
"-I- f_stc error read status message from portserver");
1482 sprintf(c_line,
"-I- f_stc error get spec. info from portserver");
1485 sprintf(c_line,
"-I- f_stc unknown message id %d", i_error);
1487 printf(
"%s\n", c_line);
1490 strcpy(c_dest, c_line);
1496 printf(
"%s\n", c_line);
1499 strcpy(c_dest, c_line);
INTS4 f_stc_close(struct s_tcpcomm *ps_tcp)
struct hostent hostentstruct
INTS4 f_stc_listenserver(struct s_tcpcomm *ps_server)
INTS4 f_stc_disperror(INTS4 i_error, CHARS *c_dest, INTS4 i_out)
INTS4 f_stc_acceptclient(struct s_tcpcomm *ps_server, INTS4 *pi_channel)
INTS4 f_stc_discclient(INTS4 i_channel)
INTS4 f_stc_connectserver(CHARS *c_node, INTS4 l_port, INTS4 *pi_channel, struct s_tcpcomm *ps_client)
struct hostent * hostentptr
INTS4 f_stc_write(INTS1 *p_buffer, INTS4 i_buflen, INTS4 i_channel)
struct sockaddr_in sock sock_name
INTS4 f_stc_createserver(INTS4 *pl_port, struct s_tcpcomm *ps_server)
INTS4 f_stc_read(INTS1 *p_buffer, INTS4 i_buflen, INTS4 i_channel, INTS4 i_timeout)