unix网络编程(unix network programming)

unix网络编程(unix network programming), 作者W.Richard Stevens, 这本书写的真是好,不愧为网络学习两部巨著中的一部。

第一部学习:
写的很细,真的很细,看别人写的网络编程的书籍,真的好多东西没有解释清楚,弄的乱乱的,看这本书,真觉得如沐春风,什么都讲得那么详细,而且连为什么这么做也讲得很好,看来看书要看经典,否则越看越糊涂!
谨记谨记!
先草草看一遍,用到网络编程的时候,一定回来好好读这本书
 2012.5.7
找到了unix网络编程第一卷第三版,原来看的是第二版的,这个版删掉了一些过时的东西,增加了sctp, 写的真的很好,现在用不到,将来再细读吧!
2012.5.12


第二部学习:
开始读unix网络编程第二卷第二版IPC, 这个在linux程序编写的时候很用到
2012.5.12
pipes have no names, and their biggest disadvantage is that they can be used only between processes that have a parent process in common
2012.5.19
如果要等待某个事件的发生,不用使用while()这样浪费时间的东东,可以使用mutex and Condition variables
read-write lock可以让读和写区别对待,这样就可以使获得read lock的锁继续read lock !
record locking,进程间同步.
2012.5.27
第十章开始,主要讲进程间通信
semaphore与mutex的不同是:1,semaphore可以设置值为N 2, mutex仅能为锁定它的线程解锁,而semaphores却可以被别的线程V操作
异步操作:例如,两个不相干的线程可以完全的异步
同步操作: 为了解决多个线程竞争某些资源而提出的解决方案。
一般情况下,mutex和condition variables用于线程同步,而semaphore用于进程同步。
semaphore分为named semaphore and memory-based semaphore( unnamed semaphore)
2012.6.2
12章shared Memory
Once the memory is mapped into the address space of the processes that are sharing the memory region, no kernel involvement occurs in passing data between the processes. What we means 'no kernel involvement' is that the processes do not execute any system calls into the kernel to pass the data.
进程同步的方法:Mutexes, condition variable, Read-Write Locking,semaphores
Normally,进程A与进程B通过FIFO,Pipe,和Queue通信,需要四次数据拷贝: 数据拷贝到kernel, 再拷贝到process A,再次进入kernel,最后传递给进程B.
进程通信,也就是传递消息的方法有:FiFO, Queue, Shared Memory,
2012.6.5
shared memory,父进程和子进程都拥有一套程序,但是mapped memory返回的指针指向了同一块内存。
posix shared memory扩展了内容,给出了不想关的进程之间shared memory implement.
posix shared memory 有两种机制:1. Memory-mapped files 2,shared memory objects
第15章与第16章
Doors are only Solaris features
16章中,introduction->history中写到,Sun RPC用于socket api来实现的,所以远程进程通信就用Socket就好了
2012.6.6
经过一个月IPC终于读完了,最重要的是明白了什么是同步,什么是进程通信,哈哈,大概看了看,用到时再仔细用
但是,我想如果编写c++代码,也使用c的进程通信吗? 例如QT中,是不是封装了进程通信的部分?
2012.6.6
如果需要在进程间传递数据,就要使用message, 而如果要同步多个进程则使用semaphore,同步多个线程则使用mutex !!!
2013.10.8
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
UNIX Network Programming Volume 2》(Unix网络编程卷2英文版,djvu格式,带绿色小巧的阅读器) 原书名: UNIX Network Programming Volume 2:Interprocess Communications 2nd ed. 原出版社: Prentice Hall/Pearson 作者: W.Richard Stevens preface part 1. introduction chapter 1. introduction 1.1 introduction 3 1.2 processes, threads, and the sharing of information 5 1.3 persistence of ipc objects 6 1.4 name spaces 7 1.5 effect of fork, exec, and exit on ipc objects 9 1.6 error handling: wrapper functions 11 1.7 unix standards 13 1.8 road map to ipc examples in the text 15 1.9 summary 16 chapter 2. posix ipc 2.1 introduction 19 2.2 ipc names 19 2.3 creating and opening ipc channels 22 2.4 ipc permissions 25 2.5 summary 26 .chapter 3. system v ipc 3.1 introduction 27 3.2 key_t keys and ftok function 28 3.3 ipc_perm structure 30 3.4 creating and opening ipc channels 30 3.5 ipc permissions 32 3.6 identifier reuse 34 3.7 ipcs and ipcrm programs 36 3.8 kernel limits 36 3.9 summary 38 part 2. message passing chapter 4. pipes and fifos 4.1 introduction 43 4.2 a simple client--server example 43 4.3 pipes 44 4.4 full-duplex pipes 50 4.5 popen and pc1ose functions 52 4.6 fifos 54 4.7 additional properties of pipes and fifos 58 4.8 one server, multiple clients 60 4.9 iterative versus concurrent servers 66 4.10 streams and messages 67 4.11 pipe and fifo limits 72 4.12 summary 73 chapter 5. posix message oueues 5.1 introduction 75 5.2 mq_open, mq_c1ose, and mq_un1ink functions 76 5.3 mq_getattr and mq_setattr functions 79 5.4 mq_send and mq_receive functions 82 5.5 message queue limits 86 5.6 mq_notify function 87 5.7 posix realtime signals 98 5.8 implementation using memory-mapped i/o 106 5.9 summary 126 chapter 6. system v message queues 6.1 introduction 129 6.2 msgget function 130 6.3 msgsnd function 131 6.4 msgrcv function 132 6.5 msgctl function 134 6.6 simple programs 135 6.7 client-server example 140 6.8 multiplexing messages 142 6.9 message queues w
Unix网络编程卷1,第三版,英文版。大名顶顶的Richard Stevens所写 目录: Copyright Addison-Wesley Professional Computing Series Foreword Preface Introduction Changes from the Second Edition Using This Book Source Code and Errata Availability Acknowledgments Part 1: Introduction and TCP/IP Chapter 1. Introduction Section 1.1. Introduction Section 1.2. A Simple Daytime Client Section 1.3. Protocol Independence Section 1.4. Error Handling: Wrapper Functions Section 1.5. A Simple Daytime Server Section 1.6. Roadmap to Client/Server Examples in the Text Section 1.7. OSI Model Section 1.8. BSD Networking History Section 1.9. Test Networks and Hosts Section 1.10. Unix Standards Section 1.11. 64-Bit Architectures Section 1.12. Summary Exercises Chapter 2. The Transport Layer: TCP, UDP, and SCTP Section 2.1. Introduction Section 2.2. The Big Picture Section 2.3. User Datagram Protocol (UDP) Section 2.4. Transmission Control Protocol (TCP) Section 2.5. Stream Control Transmission Protocol (SCTP) Section 2.6. TCP Connection Establishment and Termination Section 2.7. TIME_WAIT State Section 2.8. SCTP Association Establishment and Termination Section 2.9. Port Numbers Section 2.10. TCP Port Numbers and Concurrent Servers Section 2.11. Buffer Sizes and Limitations Section 2.12. Standard Internet Services Section 2.13. Protocol Usage by Common Internet Applications Section 2.14. Summary Exercises Part 2: Elementary Sockets Chapter 3. Sockets Introduction Section 3.1. Introduction Section 3.2. Socket Address Structures Section 3.3. Value-Result Arguments Section 3.4. Byte Ordering Functions Section 3.5. Byte Manipulation Functions Section 3.6. inet_aton, inet_addr, and inet_ntoa Functions Section 3.7. inet_pton and inet_ntop Functions Section 3.8. sock_ntop and Related Functions Section 3.9. readn, writen, and readline Functions Section 3.10. Summary Exercises Chapter 4. Elementary TCP Sockets Section 4.1. Introduction Section 4.2. socket Function Section 4.3. connect Function Section 4.4. bind Function Section 4.5. listen Function Section 4.6. accept Function Section 4.7. fork and exec Functions Section 4.8. Concurrent Servers Section 4.9. close Function Section 4.10. getsockname and getpeername Functions Section 4.11. Summary Exercises Chapter 5. TCP Client/Server Example Section 5.1. Introduction Section 5.2. TCP Echo Server: main Function Section 5.3. TCP Echo Server: str_echo Function Section 5.4. TCP Echo Client: main Function Section 5.5. TCP Echo Client: str_cli Function Section 5.6. Normal Startup Section 5.7. Normal Termination Section 5.8. POSIX Signal Handling Section 5.9. Handling SIGCHLD Signals Section 5.10. wait and waitpid Functions Section 5.11. Connection Abort before accept Returns Section 5.12. Termination of Server Process Section 5.13. SIGPIPE Signal Section 5.14. Crashing of Server Host Section 5.15. Crashing and Rebooting of Server Host Section 5.16. Shutdown of Server Host Section 5.17. Summary of TCP Example Section 5.18. Data Format Section 5.19. Summary Exercises Chapter 6. I/O Multiplexing: The select and poll Functions Section 6.1. Introduction Section 6.2. I/O Models Section 6.3. select Function Section 6.4. str_cli Function (Revisited) Section 6.5. Batch Input and Buffering Section 6.6. shutdown Function Section 6.7. str_cli Function (Revisited Again) Section 6.8. TCP Echo Server (Revisited) Section 6.9. pselect Function Section 6.10. poll Function Section 6.11. TCP Echo Server (Revisited Again) Section 6.12. Summary Exercises Chapter 7. Socket Options Section 7.1. Introduction Section 7.2. getsockopt and setsockopt Functions Section 7.3. Checking if an Option Is Supported and Obtaining the Default Section 7.4. Socket States Section 7.5. Generic Socket Options Section 7.6. IPv4 Socket Options Section 7.7. ICMPv6 Socket Option Section 7.8. IPv6 Socket Options Section 7.9. TCP Socket Options Section 7.10. SCTP Socket Options Section 7.11. fcntl Function Section 7.12. Summary Exercises Chapter 8. Elementary UDP Sockets Section 8.1. Introduction Section 8.2. recvfrom and sendto Functions Section 8.3. UDP Echo Server: main Function Section 8.4. UDP Echo Server: dg_echo Function Section 8.5. UDP Echo Client: main Function Section 8.6. UDP Echo Client: dg_cli Function Section 8.7. Lost Datagrams Section 8.8. Verifying Received Response Section 8.9. Server Not Running Section 8.10. Summary of UDP Example Section 8.11. connect Function with UDP Section 8.12. dg_cli Function (Revisited) Section 8.13. Lack of Flow Control with UDP Section 8.14. Determining Outgoing Interface with UDP Section 8.15. TCP and UDP Echo Server Using select Section 8.16. Summary Exercises Chapter 9. Elementary SCTP Sockets Section 9.1. Introduction Section 9.2. Interface Models Section 9.3. sctp_bindx Function Section 9.4. sctp_connectx Function Section 9.5. sctp_getpaddrs Function Section 9.6. sctp_freepaddrs Function Section 9.7. sctp_getladdrs Function Section 9.8. sctp_freeladdrs Function Section 9.9. sctp_sendmsg Function Section 9.10. sctp_recvmsg Function Section 9.11. sctp_opt_info Function Section 9.12. sctp_peeloff Function Section 9.13. shutdown Function Section 9.14. Notifications Section 9.15. Summary Exercises Chapter 10. SCTP Client/Server Example Section 10.1. Introduction Section 10.2. SCTP One-to-Many-Style Streaming Echo Server: main Function Section 10.3. SCTP One-to-Many-Style Streaming Echo Client: main Function Section 10.4. SCTP Streaming Echo Client: str_cli Function Section 10.5. Exploring Head-of-Line Blocking Section 10.6. Controlling the Number of Streams Section 10.7. Controlling Termination Section 10.8. Summary Exercises Chapter 11. Name and Address Conversions Section 11.1. Introduction Section 11.2. Domain Name System (DNS) Section 11.3. gethostbyname Function Section 11.4. gethostbyaddr Function Section 11.5. getservbyname and getservbyport Functions Section 11.6. getaddrinfo Function Section 11.7. gai_strerror Function Section 11.8. freeaddrinfo Function Section 11.9. getaddrinfo Function: IPv6 Section 11.10. getaddrinfo Function: Examples Section 11.11. host_serv Function Section 11.12. tcp_connect Function Section 11.13. tcp_listen Function Section 11.14. udp_client Function Section 11.15. udp_connect Function Section 11.16. udp_server Function Section 11.17. getnameinfo Function Section 11.18. Re-entrant Functions Section 11.19. gethostbyname_r and gethostbyaddr_r Functions Section 11.20. Obsolete IPv6 Address Lookup Functions Section 11.21. Other Networking Information Section 11.22. Summary Exercises Part 3: Advanced Sockets Chapter 12. IPv4 and IPv6 Interoperability Section 12.1. Introduction Section 12.2. IPv4 Client, IPv6 Server Section 12.3. IPv6 Client, IPv4 Server Section 12.4. IPv6 Address-Testing Macros Section 12.5. Source Code Portability Section 12.6. Summary Exercises Chapter 13. Daemon Processes and the inetd Superserver Section 13.1. Introduction Section 13.2. syslogd Daemon Section 13.3. syslog Function Section 13.4. daemon_init Function Section 13.5. inetd Daemon Section 13.6. daemon_inetd Function Section 13.7. Summary Exercises Chapter 14. Advanced I/O Functions Section 14.1. Introduction Section 14.2. Socket Timeouts Section 14.3. recv and send Functions Section 14.4. readv and writev Functions Section 14.5. recvmsg and sendmsg Functions Section 14.6. Ancillary Data Section 14.7. How Much Data Is Queued? Section 14.8. Sockets and Standard I/O Section 14.9. Advanced Polling Section 14.10. Summary Exercises Chapter 15. Unix Domain Protocols Section 15.1. Introduction Section 15.2. Unix Domain Socket Address Structure Section 15.3. socketpair Function Section 15.4. Socket Functions Section 15.5. Unix Domain Stream Client/Server Section 15.6. Unix Domain Datagram Client/Server Section 15.7. Passing Descriptors Section 15.8. Receiving Sender Credentials Section 15.9. Summary Exercises Chapter 16. Nonblocking I/O Section 16.1. Introduction Section 16.2. Nonblocking Reads and Writes: str_cli Function (Revisited) Section 16.3. Nonblocking connect Section 16.4. Nonblocking connect: Daytime Client Section 16.5. Nonblocking connect: Web Client Section 16.6. Nonblocking accept Section 16.7. Summary Exercises Chapter 17. ioctl Operations Section 17.1. Introduction Section 17.2. ioctl Function Section 17.3. Socket Operations Section 17.4. File Operations Section 17.5. Interface Configuration Section 17.6. get_ifi_info Function Section 17.7. Interface Operations Section 17.8. ARP Cache Operations Section 17.9. Routing Table Operations Section 17.10. Summary Exercises Chapter 18. Routing Sockets Section 18.1. Introduction Section 18.2. Datalink Socket Address Structure Section 18.3. Reading and Writing Section 18.4. sysctl Operations Section 18.5. get_ifi_info Function (Revisited) Section 18.6. Interface Name and Index Functions Section 18.7. Summary Exercises Chapter 19. Key Management Sockets Section 19.1. Introduction Section 19.2. Reading and Writing Section 19.3. Dumping the Security Association Database (SADB) Section 19.4. Creating a Static Security Association (SA) Section 19.5. Dynamically Maintaining SAs Section 19.6. Summary Exercises Chapter 20. Broadcasting Section 20.1. Introduction Section 20.2. Broadcast Addresses Section 20.3. Unicast versus Broadcast Section 20.4. dg_cli Function Using Broadcasting Section 20.5. Race Conditions Section 20.6. Summary Exercises Chapter 21. Multicasting Section 21.1. Introduction Section 21.2. Multicast Addresses Section 21.3. Multicasting versus Broadcasting on a LAN Section 21.4. Multicasting on a WAN Section 21.5. Source-Specific Multicast Section 21.6. Multicast Socket Options Section 21.7. mcast_join and Related Functions Section 21.8. dg_cli Function Using Multicasting Section 21.9. Receiving IP Multicast Infrastructure Session Announcements Section 21.10. Sending and Receiving Section 21.11. Simple Network Time Protocol (SNTP) Section 21.12. Summary Exercises Chapter 22. Advanced UDP Sockets Section 22.1. Introduction Section 22.2. Receiving Flags, Destination IP Address, and Interface Index Section 22.3. Datagram Truncation Section 22.4. When to Use UDP Instead of TCP Section 22.5. Adding Reliability to a UDP Application Section 22.6. Binding Interface Addresses Section 22.7. Concurrent UDP Servers Section 22.8. IPv6 Packet Information Section 22.9. IPv6 Path MTU Control Section 22.10. Summary Exercises Chapter 23. Advanced SCTP Sockets Section 23.1. Introduction Section 23.2. An Autoclosing One-to-Many-Style Server Section 23.3. Partial Delivery Section 23.4. Notifications Section 23.5. Unordered Data Section 23.6. Binding a Subset of Addresses Section 23.7. Determining Peer and Local Address Information Section 23.8. Finding an Association ID Given an IP Address Section 23.9. Heartbeating and Address Failure Section 23.10. Peeling Off an Association Section 23.11. Controlling Timing Section 23.12. When to Use SCTP Instead of TCP Section 23.13. Summary Exercises Chapter 24. Out-of-Band Data Section 24.1. Introduction Section 24.2. TCP Out-of-Band Data Section 24.3. sockatmark Function Section 24.4. TCP Out-of-Band Data Recap Section 24.5. Summary Exercises Chapter 25. Signal-Driven I/O Section 25.1. Introduction Section 25.2. Signal-Driven I/O for Sockets Section 25.3. UDP Echo Server Using SIGIO Section 25.4. Summary Exercises Chapter 26. Threads Section 26.1. Introduction Section 26.2. Basic Thread Functions: Creation and Termination Section 26.3. str_cli Function Using Threads Section 26.4. TCP Echo Server Using Threads Section 26.5. Thread-Specific Data Section 26.6. Web Client and Simultaneous Connections (Continued) Section 26.7. Mutexes: Mutual Exclusion Section 26.8. Condition Variables Section 26.9. Web Client and Simultaneous Connections (Continued) Section 26.10. Summary Exercises Chapter 27. IP Options Section 27.1. Introduction Section 27.2. IPv4 Options Section 27.3. IPv4 Source Route Options Section 27.4. IPv6 Extension Headers Section 27.5. IPv6 Hop-by-Hop Options and Destination Options Section 27.6. IPv6 Routing Header Section 27.7. IPv6 Sticky Options Section 27.8. Historical IPv6 Advanced API Section 27.9. Summary Exercises Chapter 28. Raw Sockets Section 28.1. Introduction Section 28.2. Raw Socket Creation Section 28.3. Raw Socket Output Section 28.4. Raw Socket Input Section 28.5. ping Program Section 28.6. traceroute Program Section 28.7. An ICMP Message Daemon Section 28.8. Summary Exercises Chapter 29. Datalink Access Section 29.1. Introduction Section 29.2. BSD Packet Filter (BPF) Section 29.3. Datalink Provider Interface (DLPI) Section 29.4. Linux: SOCK_PACKET and PF_PACKET Section 29.5. libpcap: Packet Capture Library Section 29.6. libnet: Packet Creation and Injection Library Section 29.7. Examining the UDP Checksum Field Section 29.8. Summary Exercises Chapter 30. Client/Server Design Alternatives Section 30.1. Introduction Section 30.2. TCP Client Alternatives Section 30.3. TCP Test Client Section 30.4. TCP Iterative Server Section 30.5. TCP Concurrent Server, One Child per Client Section 30.6. TCP Preforked Server, No Locking Around accept Section 30.7. TCP Preforked Server, File Locking Around accept Section 30.8. TCP Preforked Server, Thread Locking Around accept Section 30.9. TCP Preforked Server, Descriptor Passing Section 30.10. TCP Concurrent Server, One Thread per Client Section 30.11. TCP Prethreaded Server, per-Thread accept Section 30.12. TCP Prethreaded Server, Main Thread accept Section 30.13. Summary Exercises Chapter 31. Streams Section 31.1. Introduction Section 31.2. Overview Section 31.3. getmsg and putmsg Functions Section 31.4. getpmsg and putpmsg Functions Section 31.5. ioctl Function Section 31.6. Transport Provider Interface (TPI) Section 31.7. Summary Exercises Appendix A. IPv4, IPv6, ICMPv4, and ICMPv6 Section A.1. Introduction Section A.2. IPv4 Header Section A.3. IPv6 Header Section A.4. IPv4 Addresses Section A.5. IPv6 Addresses Section A.6. Internet Control Message Protocols (ICMPv4 and ICMPv6) Appendix B. Virtual Networks Section B.1. Introduction Section B.2. The MBone Section B.3. The 6bone Section B.4. IPv6 Transition: 6to4 Appendix C. Debugging Techniques Section C.1. System Call Tracing Section C.2. Standard Internet Services Section C.3. sock Program Section C.4. Small Test Programs Section C.5. tcpdump Program Section C.6. netstat Program Section C.7. lsof Program Appendix D. Miscellaneous Source Code Section D.1. unp.h Header Section D.2. config.h Header Section D.3. Standard Error Functions Appendix E. Solutions to Selected Exercises Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18 Chapter 20 Chapter 21 Chapter 22 Chapter 24 Chapter 25 Chapter 26 Chapter 27 Chapter 28 Chapter 29 Chapter 30 Chapter 31 Bibliography

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值