HP Rp5405 BSD Sockets Interface Programmer's Guide - Page 141
Example Using UNIX Domain Stream Sockets
View all HP Rp5405 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 141 highlights
Using UNIX Domain Stream Sockets Example Using UNIX Domain Stream Sockets 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, (sizeof(struct sockaddr_un) - sizeof(short))); /* * Create the server socket */ if ((s = socket( AF_UNIX, SOCK_STREAM, 0)) == -1) { Chapter 6 141