HP Rp7410 BSD Sockets Interface Programmer's Guide - Page 142
if errno == EINTR
View all HP Rp7410 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 142 highlights
Using UNIX Domain Stream Sockets Example Using UNIX Domain Stream Sockets perror("catch - socket failed"); exit(0); } bufsize = BUFSIZE; /* * Use setsockopt() to change the socket buffer size to improve * throughput for large data transfers */ if ((setsockopt(s, SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(bufsize))) == -1) { perror("catch - setsockopt failed"); exit(0); } /* * Bind the server socket to its name */ if ((bind(s, &sa, sizeof(struct sockaddr_un))) == -1) { perror("catch - bind failed"); exit(0); } /* * Call listen() to enable reception of connection requests * (listen() will silently change given backlog 0, to be 1 instead) */ if ((listen(s, 0)) == -1) { perror("catch - listen failed"); exit(0); }next_conn: i = sizeof(struct sockaddr_un); /* * Call accept() to accept connection request. This call will block * until a connection request arrives. */ if ((ns = accept(s, &sa, &i)) == -1) { if (errno == EINTR) goto next_conn; perror("catch - accept failed"); exit(0); } if ((pid = fork()) != 0) { close(ns); goto next_conn; } /* close(s); */ /* * Receive the bullet to synchronize with the other side */ recv_data(ns, &bullet, sizeof(struct bullet)); if (bullet.magic != 12345) { printf("catch: bad magic %d\n", bullet.magic); exit(0); } bytes = bullet.bytes; recvsize = (bytes>BUFSIZE)?BUFSIZE:bytes; /* * Send the bullet back to complete synchronization 142 Chapter 6