~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to iocore/eventsystem/I_SocketManager.h

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
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
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
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.
 
22
 */
 
23
 
 
24
/****************************************************************************
 
25
 
 
26
  SocketManager.h
 
27
 
 
28
  Handle the allocation of the socket descriptor (fd) resource.
 
29
 
 
30
 
 
31
 ****************************************************************************/
 
32
 
 
33
#ifndef _I_SocketManager_h_
 
34
#define _I_SocketManager_h_
 
35
 
 
36
#include "libts.h"
 
37
#include "I_EventSystem.h"
 
38
#include "I_Thread.h"
 
39
 
 
40
#define DEFAULT_OPEN_MODE                         0644
 
41
 
 
42
class Thread;
 
43
 
 
44
#define SOCKET int
 
45
 
 
46
/** Utility class for socket operations.
 
47
 */
 
48
struct SocketManager
 
49
{
 
50
  SocketManager();
 
51
 
 
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);
 
55
 
 
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);
 
58
 
 
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);
 
65
 
 
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);
 
68
 
 
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);
 
73
 
 
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);
 
84
#if TS_USE_EPOLL
 
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);
 
89
#endif
 
90
#if TS_USE_KQUEUE
 
91
  int kqueue();
 
92
  int kevent(int kq, const struct kevent *changelist, int nchanges,
 
93
             struct kevent *eventlist, int nevents,
 
94
             const struct timespec *timeout);
 
95
#endif
 
96
#if TS_USE_PORT
 
97
  int port_create();
 
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);
 
103
#endif
 
104
  int shutdown(int s, int how);
 
105
  int dup(int s);
 
106
 
 
107
  // result is the fd or -errno
 
108
  int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
 
109
 
 
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);
 
115
 
 
116
  int getsockname(int s, struct sockaddr *, socklen_t *);
 
117
 
 
118
  /** Close the socket.
 
119
      @return 0 if successful, -errno on error.
 
120
   */
 
121
  int close(int sock);
 
122
  int ink_bind(int s, struct sockaddr *name, int namelen, short protocol = 0);
 
123
 
 
124
  int pagesize;
 
125
 
 
126
  virtual ~ SocketManager();
 
127
 
 
128
private:
 
129
  // just don't do it
 
130
    SocketManager(SocketManager &);
 
131
    SocketManager & operator=(SocketManager &);
 
132
};
 
133
 
 
134
extern SocketManager socketManager;
 
135
 
 
136
#endif /*_SocketManager_h_*/