HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual page 142

Bsd sockets interface programmer’s guide
Hide thumbs Also See for Rp3440-4 - 9000 - 0 MB RAM:
Table of Contents

Advertisement

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

Advertisement

Table of Contents
loading

Table of Contents