-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhoma_socket.h
91 lines (73 loc) · 2.38 KB
/
homa_socket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef HOMA_SOCKET_H
#define HOMA_SOCKET_H
#include <deque>
#include "src/core/lib/iomgr/ev_posix.h"
#include "homa.h"
/**
* An instance of this class stores state associated with an open Homa
* socket. It particular, it manages the buffer region used for
* incoming messages.
*/
class HomaSocket {
public:
HomaSocket(int domain, int port);
HomaSocket(uint8_t *bufRegion);
~HomaSocket(void);
void saveBuffers(struct homa_recvmsg_args *recvArgs);
void getSavedBuffers(struct homa_recvmsg_args *recvArgs);
//Returns the file descriptor associated with this object, or -1
// if the constructor failed to initialize the socket.
inline int getFd() const
{
return fd;
}
/**
* Returns GRPCs handle for the file descriptor for this socket, or
* nullptr if the socket was not successfully opened.
*/
inline grpc_fd *getGfd() const
{
return gfd;
}
/**
* Returns the port number associated with this socket, or zero if
* if the constructor failed to initialize the socket.
*/
inline int getPort() const
{
return port;
}
/**
* Returns the base address of the receive buffer region for this
* socket. If the constructor failed to initialize the socket then
* nullptr is returned.
* @return
*/
inline uint8_t *getBufRegion() const
{
return bufRegion;
}
// The info below should be treated as private; it is left public
// in order to enable unit testing.
// File descriptor for a Homa socket, or -1 if the constructor
// failed to set up the socket properly.
int fd;
// GRPC token corresponding to fd, or nullptr if the constructor failed.
grpc_fd *gfd;
// Homa port number assigned to this socket.
int port;
// First byte of memory region for buffer space for incoming messages.
// or nullptr if buffer space has not been allocated. This is an mmapped
// region.
uint8_t *bufRegion;
// Size of the buffer region at *bufRegion, in bytes.
size_t bufSize;
// Tokens for buffers that need to be returned eventually to Homa.
// Each token is an entry from the buffers array in a
// struct homa_recvmsg_control object.
std::deque<uint32_t> savedBuffers;
// Must be held whenever accessing savedBuffers.
grpc_core::Mutex mutex;
void cleanup();
};
#endif // HOMA_SOCK