• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

I_SocketManager.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /****************************************************************************
00025 
00026   SocketManager.h
00027 
00028   Handle the allocation of the socket descriptor (fd) resource.
00029 
00030 
00031  ****************************************************************************/
00032 
00033 #ifndef _I_SocketManager_h_
00034 #define _I_SocketManager_h_
00035 
00036 #include "libts.h"
00037 #include "I_EventSystem.h"
00038 #include "I_Thread.h"
00039 
00040 #define DEFAULT_OPEN_MODE                         0644
00041 
00042 class Thread;
00043 extern int net_config_poll_timeout;
00044 
00045 #define SOCKET int
00046 
00047 /** Utility class for socket operations.
00048  */
00049 struct SocketManager
00050 {
00051   SocketManager();
00052 
00053   // result is the socket or -errno
00054   SOCKET socket(int domain = AF_INET, int type = SOCK_STREAM, int protocol = 0, bool bNonBlocking = true);
00055   SOCKET mc_socket(int domain = AF_INET, int type = SOCK_DGRAM, int protocol = 0, bool bNonBlocking = true);
00056 
00057   // result is the fd or -errno
00058   int open(const char *path, int oflag = O_RDWR | O_NDELAY | O_CREAT, mode_t mode = DEFAULT_OPEN_MODE);
00059 
00060   // result is the number of bytes or -errno
00061   int64_t read(int fd, void *buf, int len, void *pOLP = NULL);
00062   int64_t vector_io(int fd, struct iovec *vector, size_t count, int read_request, void *pOLP = 0);
00063   int64_t readv(int fd, struct iovec *vector, size_t count);
00064   int64_t read_vector(int fd, struct iovec *vector, size_t count, void *pOLP = 0);
00065   int64_t pread(int fd, void *buf, int len, off_t offset, char *tag = NULL);
00066 
00067   int recv(int s, void *buf, int len, int flags);
00068   int recvfrom(int fd, void *buf, int size, int flags, struct sockaddr *addr, socklen_t *addrlen);
00069 
00070   int64_t write(int fd, void *buf, int len, void *pOLP = NULL);
00071   int64_t writev(int fd, struct iovec *vector, size_t count);
00072   int64_t write_vector(int fd, struct iovec *vector, size_t count, void *pOLP = 0);
00073   int64_t pwrite(int fd, void *buf, int len, off_t offset, char *tag = NULL);
00074 
00075   int send(int fd, void *buf, int len, int flags);
00076   int sendto(int fd, void *buf, int len, int flags, struct sockaddr const* to, int tolen);
00077   int sendmsg(int fd, struct msghdr *m, int flags, void *pOLP = 0);
00078   int64_t lseek(int fd, off_t offset, int whence);
00079   int fstat(int fd, struct stat *);
00080   int unlink(char *buf);
00081   int fsync(int fildes);
00082   int ftruncate(int fildes, off_t length);
00083   int lockf(int fildes, int function, off_t size);
00084   int poll(struct pollfd *fds, unsigned long nfds, int timeout);
00085 #if TS_USE_EPOLL
00086   int epoll_create(int size);
00087   int epoll_close(int eps);
00088   int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
00089   int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout = net_config_poll_timeout);
00090 #endif
00091 #if TS_USE_KQUEUE
00092   int kqueue();
00093   int kevent(int kq, const struct kevent *changelist, int nchanges,
00094              struct kevent *eventlist, int nevents,
00095              const struct timespec *timeout);
00096 #endif
00097 #if TS_USE_PORT
00098   int port_create();
00099   int port_associate(int port, int fd, uintptr_t obj,
00100                      int events, void *user);
00101   int port_dissociate(int port, int fd, uintptr_t obj);
00102   int port_getn(int port, port_event_t *list, uint_t max,
00103                 uint_t *nget, timespec_t *timeout);
00104 #endif
00105   int shutdown(int s, int how);
00106   int dup(int s);
00107 
00108   // result is the fd or -errno
00109   int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
00110 
00111   // manipulate socket buffers
00112   int get_sndbuf_size(int s);
00113   int get_rcvbuf_size(int s);
00114   int set_sndbuf_size(int s, int size);
00115   int set_rcvbuf_size(int s, int size);
00116 
00117   int getsockname(int s, struct sockaddr *, socklen_t *);
00118 
00119   /** Close the socket.
00120       @return 0 if successful, -errno on error.
00121    */
00122   int close(int sock);
00123   int ink_bind(int s, struct sockaddr const* name, int namelen, short protocol = 0);
00124 
00125   const size_t pagesize;
00126 
00127   virtual ~ SocketManager();
00128 
00129 private:
00130   // just don't do it
00131     SocketManager(SocketManager &);
00132     SocketManager & operator=(SocketManager &);
00133 };
00134 
00135 extern SocketManager socketManager;
00136 
00137 #endif /*_SocketManager_h_*/

Generated by  doxygen 1.7.1