MCPcopy Create free account
hub / github.com/acl-dev/acl / open

Method open

lib_acl_cpp/src/stream/server_socket.cpp:92–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92bool server_socket::open(const char* addr)
93{
94 if (fd_ != ACL_SOCKET_INVALID) {
95 logger_error("listen fd already opened, fd_=%d", (int) fd_);
96 return true;
97 }
98
99#ifdef ACL_UNIX
100 if (acl_valid_unix(addr)) {
101 fd_ = acl_unix_listen(addr, backlog_, open_flag_);
102 unix_sock_ = true;
103 addr_ = addr;
104 } else
105#endif
106 {
107 fd_ = acl_inet_listen(addr, backlog_, open_flag_);
108 unix_sock_ = false;
109 }
110
111 if (fd_ == ACL_SOCKET_INVALID) {
112 logger_error("listen %s error %s", addr, last_serror());
113 unix_sock_ = false;
114 addr_ = addr;
115 return false;
116 }
117
118 // �����ɱ����������ľ�����Ա��������������н���ر�
119 fd_local_ = fd_;
120
121 if (unix_sock_) {
122 return true;
123 }
124
125 // ֮�������� getsockname ���»��һЩ������ַ����Ҫ��Ϊ��Ӧ�Ե�����
126 // �� addr Ϊ ip:0 �����Σ����������ĵ�ַ�еĶ˿�Ϊ 0 ʱҪ�����ϵͳ
127 // �Զ�����һ���˿ں�
128 char buf[512];
129 if (acl_getsockname(fd_, buf, sizeof(buf)) < 0) {
130 logger_error("getsockname error: %s", acl_last_serror());
131 addr_ = addr;
132 } else {
133 addr_ = buf;
134 }
135 return true;
136}
137
138ACL_SOCKET server_socket::unbind()
139{

Callers 1

acceptMethod · 0.45

Calls 6

acl_valid_unixFunction · 0.85
acl_unix_listenFunction · 0.85
acl_inet_listenFunction · 0.85
acl_getsocknameFunction · 0.85
acl_last_serrorFunction · 0.85
last_serrorFunction · 0.50

Tested by

no test coverage detected