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

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

Advertisement

cc = send(fd, buf, buflen, 0);
if (cc == -1) {
perror("send");
exit(0);
}
buf += cc;
buflen -= cc;
}
}
recv_data(fd, buf, buflen)
char *buf;
{
int cc;
while (buflen > 0) {
cc = recv(fd, buf, buflen, 0);
if (cc == -1) {
perror("recv");
exit(0);
}
buf += cc;
buflen -= cc;
}
}
main(argc, argv)
int argc;
char *argv[];
{
int bufsize, bytes, cc, i, total, pid, counter_pid;
float msec;
struct timeval tp1, tp2;
int ns, recvsize, secs, usec;
struct timezone tzp;
struct sockaddr_un sa;
/*
* The SIGPIPE signal will be received if the peer has gone away
* and an attempt is made to write data to the peer. Ignoring this
* signal causes the write operation to receive an EPIPE error.
* Thus, the user is informed about what happened.
*/
signal(SIGPIPE, SIG_IGN);
signal(SIGCLD, SIG_IGN);
signal(SIGINT, timeout);
setbuf(stdout, 0);
setbuf(stderr, 0);
if (argc > 1) {
argv++;
counter_pid = atoi(*argv++);
} else
counter_pid = 0;
/*
* Set up the socket variables - address family, socket name.
* They'll be used later to bind() the name to the server socket.
*/
sa.sun_family = AF_UNIX;
strncpy(sa.sun_path, SOCKNAME,
/*
* Create the server socket
*/
if ((s = socket( AF_UNIX, SOCK_STREAM, 0)) == -1) {
Chapter 6
Example Using UNIX Domain Stream Sockets
(sizeof(struct sockaddr_un) - sizeof(short)));
Using UNIX Domain Stream Sockets
141

Advertisement

Table of Contents
loading

Table of Contents