+
+int
+xsocket (int domain, int type, int protocol)
+{
+ int ret;
+
+ ret = socket (domain, type, protocol);
+ if (ret == -1) {
+ fprintf (stderr, "Error: socket failed: %s. Aborting.\n",
+ strerror (errno));
+ exit (1);
+ }
+
+ return ret;
+}
+
+void
+xbind (int sockfd, const struct sockaddr *my_addr, socklen_t addrlen)
+{
+ int ret;
+
+ ret = bind (sockfd, my_addr, addrlen);
+ if (ret == -1) {
+ fprintf (stderr, "Error: bind failed: %s. Aborting.\n",
+ strerror (errno));
+ exit (1);
+ }
+}
+
+ttt_status_t
+xconnect (int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
+{
+ int ret;
+
+ ret = connect (sockfd, serv_addr, addrlen);
+ if (ret == -1) {
+ switch (errno) {
+ case ECONNREFUSED:
+ return TTT_STATUS_CONNECTION_REFUSED;
+ case EHOSTUNREACH:
+ case ENETUNREACH:
+ return TTT_STATUS_NETWORK_UNREACHABLE;
+ default:
+ fprintf (stderr, "Error: connect failed (errno = %d): %s. Aborting.\n",
+ errno, strerror (errno));
+ exit (1);
+ }
+ }
+
+ return TTT_STATUS_SUCCESS;
+}
+
+void
+xlisten (int s, int backlog)
+{
+ int ret;
+
+ ret = listen (s, backlog);
+ if (ret == -1) {
+ fprintf (stderr, "Error: listen failed: %s. Aborting.\n",
+ strerror (errno));
+ exit (1);
+ }
+}
+
+int
+xfcntl (int fd, int cmd, long arg)
+{
+ int ret;
+
+ ret = fcntl (fd, cmd, arg);
+ if (ret == -1) {
+ fprintf (stderr, "Error: fcntl failed: %s. Aborting.\n",
+ strerror (errno));
+ exit (1);
+ }
+
+ return ret;
+}
+
+int
+xselect (int n,
+ fd_set *readfds,
+ fd_set *writefds,
+ fd_set *exceptfds,
+ struct timeval *timeout)
+{
+ int ret;
+
+ ret = select (n, readfds, writefds, exceptfds, timeout);
+ if (ret == -1) {
+ fprintf (stderr, "Error: select failed: %s. Aborting.\n",
+ strerror (errno));
+ exit (1);
+ }
+
+ return ret;
+}
+
+ssize_t
+xread (int fd, void *buf, size_t count)
+{
+ int ret;
+
+ ret = read (fd, buf, count);
+ if (ret == -1) {
+ fprintf (stderr, "Error: read failed: %s. Aborting.\n",
+ strerror (errno));
+ exit (1);
+ }
+
+ return ret;
+}
+
+ssize_t
+xwrite (int fd, const void *buf, size_t count)
+{
+ int ret;
+
+ ret = write (fd, buf, count);
+ if (ret == -1) {
+ fprintf (stderr, "Error: write failed: %s. Aborting.\n",
+ strerror (errno));
+ exit (1);
+ }
+
+ return ret;
+}