| 182 | } |
| 183 | |
| 184 | int SocketMap::Init(const SocketMapOptions& options) { |
| 185 | if (_options.socket_creator != NULL) { |
| 186 | LOG(ERROR) << "Already initialized"; |
| 187 | return -1; |
| 188 | } |
| 189 | _options = options; |
| 190 | if (_options.socket_creator == NULL) { |
| 191 | LOG(ERROR) << "SocketOptions.socket_creator must be set"; |
| 192 | return -1; |
| 193 | } |
| 194 | if (_map.init(_options.suggested_map_size, 70) != 0) { |
| 195 | LOG(ERROR) << "Fail to init _map"; |
| 196 | return -1; |
| 197 | } |
| 198 | if (_options.idle_timeout_second_dynamic != NULL || |
| 199 | _options.idle_timeout_second > 0) { |
| 200 | bthread_attr_t attr = BTHREAD_ATTR_NORMAL; |
| 201 | bthread_attr_set_name(&attr, "RunWatchConnections"); |
| 202 | if (bthread_start_background(&_close_idle_thread, &attr, |
| 203 | RunWatchConnections, this) != 0) { |
| 204 | LOG(FATAL) << "Fail to start bthread"; |
| 205 | return -1; |
| 206 | } |
| 207 | _has_close_idle_thread = true; |
| 208 | } |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | void SocketMap::Print(std::ostream& os) { |
| 213 | // TODO: Elaborate. |
no test coverage detected