Discover unix network programming volume 1, include the articles, news, trends, analysis and practical advice about unix network programming volume 1 on alibabacloud.com
Source The preceding section describes the configuration of the function of Library 1 in the UNIX Network Programming volume. But there is another configuration in volume 2, and the functions related to inter-process communicatio
This article is senlie original, reproduced Please retain this address: http://blog.csdn.net/zhengsenlie
1. The traditional concurrent server calls fork to derive a sub-process to process each customer2. The problem with traditional concurrent servers is that it takes CPU time to fork a sub-process at each customer's site.
/* Include serv01 */# include "unp. H "intmain (INT argc, char ** argv) {intlistenfd, connfd; pid_tchildpid; voidsig_chld (INT),
This article is Senlie original. Reprint please keep this address:Http://blog.csdn.net/zhengsenlie1. Traditional concurrent server call fork derives a child process to process each customer2. The problem with traditional concurrent server is that it takes more CPU time to fork a sub-process per customer site./* Include SERV01 */#include "unp.h" intmain (int argc, char **argv) {INTLISTENFD, connfd;pid_tchildpid;voidsig_chld (int) , Sig_int (int), web_child (int), Socklen_tclilen, addrlen;struct s
This article is Senlie original, reprint please retain this address:Http://blog.csdn.net/zhengsenlie1. Pre-Create a thread pool and have each thread call the Accept2. Use a mutex instead of having each thread block in the Accept callThe thread structure that is used to maintain information about each thread the typedef struct {pthread_tthread_tid;/* Threads ID */longthread_count;/* processing the number of connections */} Thread; thread*tptr;/* the thread structure pointer to a calloc-generated
and send it to the server while (fgets (sendline, maxline, FP )! = NULL) writen (sockfd, sendline, strlen (sendline); // read EOF in stdin, input ends, close write socket Shutdown (sockfd, shut_wr ); /* EOF on stdin, send fin * // The parent process completes the data prepare. Call pause to bring yourself into sleep state pause (); return ;}
Threaded version:
/*** TCP uses two threads **/# include "unpthread. H "Void * copyto (void *); static intsockfd;/* Global for both threads to access */st
This article is senlie original, reproduced Please retain this address: http://blog.csdn.net/zhengsenlie
1. Only let your process call accept, and then "pass" the accepted connected socket to a sub-process.In this way, you do not need to provide lock protection because all sub-processes call accept.2. The parent process must track the idle status of the child process to pass a new socket to the idle child process.
Typedef struct {pid_tchild_pid;/* th
This article is Senlie original, reprint please retain this address: Http://blog.csdn.net/zhengsenlie1. After creating a thread pool in the program startup phase, just let the main thread call accept and pass the client connection to an available thread in the pool.Used to maintain information-based thread structure for each thread typedef struct {pthread_tthread_tid;/* thread ID */longthread_count;/* processing the number of connections */} Thread; thread*tptr;/* the thread structure pointer to
This article is Senlie original, reprint please retain this address:Http://blog.csdn.net/zhengsenlie1. File lock file system operation, more time-consuming2. Thread locking is not only suitable for locking between threads in the same process, but also for locking between different processes.3. Use thread lockout requirements between different processes:1) The mutex variable must be stored in a memory area shared by all processes2) must inform the thre
This article is Senlie original, reprint please retain this address: Http://blog.csdn.net/zhengsenlie1. After a thread pool is created in the program startup phase, only the main thread calls accept and passes the client connection to one of the available threads in the pool.The thread structure that is used to maintain information about each thread the typedef struct {pthread_tthread_tid;/* Threads ID */longthread_count;/* processing the number of connections */} Thread; thread*tptr;/* the thre
This article is Senlie original, reprint please retain this address:Http://blog.csdn.net/zhengsenlie1. Create a thread for each customer request in lieu of deriving a child process for each customer/* include serv06 */#include "unpthread.h" intmain (int argc, char **argv) {INTLISTENFD, Connfd;voidsig_int (int); Void*doit (void *);p Thread_ttid;socklen_tclilen, Addrlen;struct sockaddr*cliaddr;//1. Create a listener socket if (argc = = 2) LISTENFD = Tcp
This article is a computer Class of high-quality pre-sale recommendation >>>> UNIX Network Programming Volume 1: Socket Networking APIUNIX and Network specialist W. Richard Stevens's masterpiece, the world's leading
"UNIX Network Programming Volume 1" Source code can be downloaded from www.unpbook.com. The directory after decompression is unpv13e.1. CompilingTo enter the unpv13e directory, compile as follows:
Original: http://cstdlib.com/tech/2014/10/09/read-unix-network-programming-1/The article is written very clearly, suitable for beginnersRecently read the "UNIX Network programming
to readable intreadable_timeo (int fd, int Sec) {fd_setrset; struct timevaltv; // 1. set the descriptor set fd_zero ( rset); fd_set (FD, rset); // 2. set the number of seconds to wait TV. TV _sec = sec; TV. TV _usec = 0; // 3. blocking return (select (FD + 1, rset, null, null, TV) on select )); /* 4> 0 if descriptor is readable */}/* end readable_timeo */intreadable_timeo (int fd, int Sec) {INTN; If (n
UNIX Network ProgrammingVolume 1: The sockets networking API.Compile issue solution for the 2nd and 3rd edition
Firstly please read the README and follow up.
CD unpv13e./Configure
CD libMakeGcc-g-O2-d_reentrant-wall-c-o connect_nonb.o connect_nonb.cIn file encoded ded from connect_nonb.c: 1:Unp. h: 114: redefinition of
Learning UNP Network programming, tree examples exist #include "unp.h", it is necessary to configure the environment.
1. Download unpv13e to the resource page
2. Extract and move unpv13e to the appropriate folder
3. Compile
>$ CD unpv13e
>~unpv13e/$./configure
>~unpv13e/$ cd lib
>~unpv13e/lib/$ make
>~ unpv13e/lib/$ CD ... /libfree
>~unpv13e/libfree/$ Make
The UNIX volume I bought last summer has only begun to look very ashamed, and I am ashamed that the first program has been on and off for a few days, so I have to write a program, and I am looking for a job soon, the following describes how to run the first program in this book:
Search various blogs
I use Ubuntu 13.04 as the system.
Thanks to the blog: After the portal, you must record your various problems
Chapter 1
Chapter 2 TCP
Server passive open (passive open): Socket, bind, listen. The client is actively opened via the socket, connect (active open). Accept and connect are blocked
UDP UDP can be a full-duplex Chapter 3 - byte sort function
Low-order bytes are stored in the start Address: small End (Little-endian) byte order; high-order bytes are stored in the start address: big-endian (Big-endian) byte order. The Internet protocol uses big-endian
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.