1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18
19#ifndef BRPC_SOCKET_ID_H
20#define BRPC_SOCKET_ID_H
21
22// To brpc developers: This is a header included by user, don't depend
23// on internal structures, use opaque pointers instead.
24
25#include <stdint.h> // uint64_t
26#include "butil/unique_ptr.h" // std::unique_ptr
27
28
29namespace brpc {
30
31// Unique identifier of a Socket.
32// Users shall store SocketId instead of Sockets and call Socket::Address()
33// to convert the identifier to an unique_ptr at each access. Whenever a
34// unique_ptr is not destructed, the enclosed Socket will not be recycled.
35typedef uint64_t SocketId;
36
37const SocketId INVALID_SOCKET_ID = (SocketId)-1;
38
39class Socket;
40
41extern void DereferenceSocket(Socket*);
42
43struct SocketDeleter {
44 void operator()(Socket* m) const {
45 DereferenceSocket(m);
46 }
47};
48
49typedef std::unique_ptr<Socket, SocketDeleter> SocketUniquePtr;
50
51} // namespace brpc
52
53
54#endif // BRPC_SOCKET_ID_H
55