3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
24
/****************************************************************************
28
Handle the allocation of the socket descriptor (fd) resource.
31
****************************************************************************/
33
#ifndef _I_SocketManager_h_
34
#define _I_SocketManager_h_
37
#include "I_EventSystem.h"
40
#define DEFAULT_OPEN_MODE 0644
46
/** Utility class for socket operations.
52
// result is the socket or -errno
53
SOCKET socket(int domain = AF_INET, int type = SOCK_STREAM, int protocol = 0, bool bNonBlocking = true);
54
SOCKET mc_socket(int domain = AF_INET, int type = SOCK_DGRAM, int protocol = 0, bool bNonBlocking = true);
56
// result is the fd or -errno
57
int open(const char *path, int oflag = O_RDWR | O_NDELAY | O_CREAT, mode_t mode = DEFAULT_OPEN_MODE);
59
// result is the number of bytes or -errno
60
int64_t read(int fd, void *buf, int len, void *pOLP = NULL);
61
int64_t vector_io(int fd, struct iovec *vector, size_t count, int read_request, void *pOLP = 0);
62
int64_t readv(int fd, struct iovec *vector, size_t count);
63
int64_t read_vector(int fd, struct iovec *vector, size_t count, void *pOLP = 0);
64
int64_t pread(int fd, void *buf, int len, off_t offset, char *tag = NULL);
66
int recv(int s, void *buf, int len, int flags);
67
int recvfrom(int fd, void *buf, int size, int flags, struct sockaddr *addr, socklen_t *addrlen);
69
int64_t write(int fd, void *buf, int len, void *pOLP = NULL);
70
int64_t writev(int fd, struct iovec *vector, size_t count);
71
int64_t write_vector(int fd, struct iovec *vector, size_t count, void *pOLP = 0);
72
int64_t pwrite(int fd, void *buf, int len, off_t offset, char *tag = NULL);
74
int send(int fd, void *buf, int len, int flags);
75
int sendto(int fd, void *buf, int len, int flags, struct sockaddr *to, int tolen);
76
int sendmsg(int fd, struct msghdr *m, int flags, void *pOLP = 0);
77
int64_t lseek(int fd, off_t offset, int whence);
78
int fstat(int fd, struct stat *);
79
int unlink(char *buf);
80
int fsync(int fildes);
81
int ftruncate(int fildes, off_t length);
82
int lockf(int fildes, int function, off_t size);
83
int poll(struct pollfd *fds, unsigned long nfds, int timeout);
85
int epoll_create(int size);
86
int epoll_close(int eps);
87
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
88
int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);
92
int kevent(int kq, const struct kevent *changelist, int nchanges,
93
struct kevent *eventlist, int nevents,
94
const struct timespec *timeout);
98
int port_associate(int port, int fd, uintptr_t obj,
99
int events, void *user);
100
int port_dissociate(int port, int fd, uintptr_t obj);
101
int port_getn(int port, port_event_t *list, uint_t max,
102
uint_t *nget, timespec_t *timeout);
104
int shutdown(int s, int how);
107
// result is the fd or -errno
108
int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
110
// manipulate socket buffers
111
int get_sndbuf_size(int s);
112
int get_rcvbuf_size(int s);
113
int set_sndbuf_size(int s, int size);
114
int set_rcvbuf_size(int s, int size);
116
int getsockname(int s, struct sockaddr *, socklen_t *);
118
/** Close the socket.
119
@return 0 if successful, -errno on error.
122
int ink_bind(int s, struct sockaddr *name, int namelen, short protocol = 0);
126
virtual ~ SocketManager();
130
SocketManager(SocketManager &);
131
SocketManager & operator=(SocketManager &);
134
extern SocketManager socketManager;
136
#endif /*_SocketManager_h_*/