1 // Copyright 2010, Shuo Chen.  All rights reserved.
2 // http://code.google.com/p/muduo/
3 //
4 // Use of this source code is governed by a BSD-style license
5 // that can be found in the License file.
6 
7 // Author: Shuo Chen (chenshuo at chenshuo dot com)
8 //
9 // This is an internal header file, you should not include this.
10 
11 #ifndef MUDUO_NET_SOCKETSOPS_H
12 #define MUDUO_NET_SOCKETSOPS_H
13 
14 #include <arpa/inet.h>
15 #include <endian.h>
16 
17 namespace muduo
18 {
19 namespace sockets
20 {
21 
22 inline uint64_t hostToNetwork64(uint64_t host64)
23 {
24   return htobe64(host64);
25 }
26 
27 inline uint32_t hostToNetwork32(uint32_t host32)
28 {
29   return htonl(host32);
30 }
31 
32 inline uint16_t hostToNetwork16(uint16_t host16)
33 {
34   return htons(host16);
35 }
36 
37 inline uint64_t networkToHost64(uint64_t net64)
38 {
39   return be64toh(net64);
40 }
41 
42 inline uint32_t networkToHost32(uint32_t net32)
43 {
44   return ntohl(net32);
45 }
46 
47 inline uint16_t networkToHost16(uint16_t net16)
48 {
49   return ntohs(net16);
50 }
51 
52 ///
53 /// Creates a non-blocking socket file descriptor,
54 /// abort if any error.
55 int createNonblockingOrDie();
56 
57 void bindOrDie(int sockfd, const struct sockaddr_in& addr);
58 void listenOrDie(int sockfd);
59 int  accept(int sockfd, struct sockaddr_in* addr);
60 void close(int sockfd);
61+void shutdownWrite(int sockfd);
62 
63 void toHostPort(char* buf, size_t size,
64                 const struct sockaddr_in& addr);
65 void fromHostPort(const char* ip, uint16_t port,
66                   struct sockaddr_in* addr);
67 
68 struct sockaddr_in getLocalAddr(int sockfd);
69 
70 int getSocketError(int sockfd);
71 
72 }
73 }
74 
75 #endif  // MUDUO_NET_SOCKETSOPS_H
76