Applications written in versions of INtime prior to 4.0 will need to be converted to use the new network stack (also known as "Network7"). The API has been changed slightly to bring it into line with modern BSD standards and you need to link your application with new libraries.
Some project settings need to change to recompile your application to use the new stack. They are as follows:
The following are major changes in the implementation of the network software, and are designed to pull the stack closer to a standard implementation.
The following code demonstrates how to use fcntl() to achieve this:
Title Text |
Copy Code |
---|---|
int connect_with_timeout(char *peer, in_port_t port, long conn_to) { int rval; struct sockaddr_in addr; int flags; fd_set wfds; struct timeval tv; int s; s = socket(AF_INET, SOCK_STREAM, 0); if (s == -1) { fprintf(stderr, "socket() Error e=%d%s \n", errno, strerror(errno)); return -1; } // Set non-blocking flags = fcntl(s, F_GETFL); flags |= O_NONBLOCK; fcntl(s, F_SETFL, flags); addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = inet_addr(peer); rval = connect(s, (struct sockaddr *)&addr, sizeof(addr)); if (rval < 0) { // connect() retuns EINPROGRESS when non-blocking if (errno == EINPROGRESS) { tv.tv_sec = conn_to; tv.tv_usec = 0; FD_ZERO(&wfds); FD_SET(s, &wfds); if ((rval = select(s+1, NULL, &wfds, NULL, &tv)) > 0) { return s; } else if (rval == 0) { fprintf(stderr, "Timeout! \n"); shutdown(s,SHUT_RDWR); errno = ETIMEDOUT; return -1; } else { fprintf(stderr, "select() Error e=%d%s \n", errno, strerror(errno)); shutdown(s,SHUT_RDWR); return -1; } } else { fprintf(stderr, "connect() Error e=%d%s \n", errno, strerror(errno)); shutdown(s,SHUT_RDWR); return -1; } } else { fprintf(stderr, "Error connecting %d%s\n", errno, strerror(errno)); shutdown(s,SHUT_RDWR); return -1; } // Set to blocking mode again... flags = fcntl(s, F_GETFL); flags &= (~O_NONBLOCK); fcntl(s, F_SETFL, flags); return s; } |
The following are features new to INtime networking.