/usr/include/omniORB4/internal/SocketCollection.h is in libomniorb4-dev 4.2.2-0.8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | // -*- Mode: C++; -*-
// Package : omniORB
// SocketCollection.h Created on: 23 Jul 2001
// Author : Sai Lai Lo (sll)
// Author : Duncan Grisby
//
// Copyright (C) 2005-2013 Apasphere Ltd.
// Copyright (C) 2001 AT&T Laboratories Cambridge
//
// This file is part of the omniORB library
//
// The omniORB library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library. If not, see http://www.gnu.org/licenses/
//
//
// Description:
// *** PROPRIETARY INTERFACE ***
//
#ifndef __SOCKETCOLLECTION_H__
#define __SOCKETCOLLECTION_H__
#include <tcpSocket.h>
OMNI_NAMESPACE_BEGIN(omni)
class SocketCollection;
//
// Class SocketHolder holds a socket inside a collection. It contains
// flags to indicate whether the socket is selectable, and so on.
// Connection classes (e.g. tcpConnection) derive from this class.
class SocketHolder {
public:
SocketHolder(SocketHandle_t s)
: pd_socket(s),
pd_belong_to(0),
pd_shutdown(0),
pd_selectable(0),
pd_data_in_buffer(0),
pd_peeking(0),
pd_peek_go(0),
pd_nonblocking(0),
pd_peek_cond(0),
pd_fd_index(-1),
pd_next(0),
pd_prev(0) { }
virtual ~SocketHolder();
void setSelectable(int now,
CORBA::Boolean data_in_buffer,
CORBA::Boolean hold_lock=0);
// Indicate that this socket should be watched for readability.
//
// If now is 1, immediately make the socket selectable (if the
// platform permits it), rather than waiting until the select loop
// rescans.
//
// If now is 2, immediately make the socket selectable (if the
// platform permits it), but only if it is already marked
// selectable.
//
// If data_in_buffer is true, the socket is considered to already
// have data available to read.
//
// If hold_lock is true, the associated SocketCollection's lock is
// already held.
void clearSelectable();
// Indicate that this socket should not be watched any more.
CORBA::Boolean Peek();
// Watch the socket for a while to see if any data arrives. If the
// socket is not already selectable, wait for a bit in case it
// becomes selectable. Mark the socket as no longer selectable and
// return true if the socket becomes readable, otherwise return
// false.
inline void
setBlocking()
{
if (pd_nonblocking) {
tcpSocket::setBlocking(pd_socket);
pd_nonblocking = 0;
}
}
inline void
setNonBlocking()
{
if (!pd_nonblocking) {
tcpSocket::setNonBlocking(pd_socket);
pd_nonblocking = 1;
}
}
friend class SocketCollection;
protected:
SocketHandle_t pd_socket;
SocketCollection* pd_belong_to;
CORBA::Boolean pd_shutdown;
private:
CORBA::Boolean pd_selectable; // True if socket is selectable
CORBA::Boolean pd_data_in_buffer; // True if data already available
CORBA::Boolean pd_peeking; // True if a thread is currently
// peeking
CORBA::Boolean pd_peek_go; // True if the peeking thread
// should return true, even if it
// did not see data to read
CORBA::Boolean pd_nonblocking; // True if the socket is nonblocking
omni_tracedcondition* pd_peek_cond; // Condition to signal a waiting
// peeker
int pd_fd_index; // -1 if select thread is not
// watching; otherwise, index of
// the fd within the poll / select
// list.
SocketHolder* pd_next;
SocketHolder** pd_prev;
};
//
// SocketCollection manages a collection of sockets.
class SocketCollection {
public:
SocketCollection();
virtual ~SocketCollection();
virtual CORBA::Boolean notifyReadable(SocketHolder*) = 0;
// Callback used by Select(). If it returns false, something has
// gone very wrong with the collection and exits the Select loop.
// This method is called while holding pd_collection_lock.
CORBA::Boolean isSelectable(SocketHandle_t sock);
// Indicates whether the given socket can be selected upon.
CORBA::Boolean Select();
// Returns true if the Select() has successfully done a scan.
// otherwise returns false to indicate that an error has been
// detected and this function should not be called again.
//
// For each of the sockets that has been marked watchable and indeed
// has become readable, call notifyReadable() with the socket as the
// argument.
void wakeUp();
// On platforms where is is possible, immediately wake up a thread
// blocked in Select().
void incrRefCount();
void decrRefCount();
void addSocket(SocketHolder* sock);
// Add this socket to the collection. Increments this collection's
// refcount.
void removeSocket(SocketHolder* sock);
// Remove the socket from this collection. Returns the socket which
// has been removed. Decrements this collection's refcount.
static omni_time_t scan_interval;
static unsigned idle_scans;
private:
int pd_refcount;
omni_tracedmutex pd_collection_lock;
// Absolute time at which we scan through the socket list choosing
// the selectable ones.
omni_time_t pd_abs_time;
// On platforms that support it, we use a pipe to wake up the select.
int pd_pipe_read;
int pd_pipe_write;
CORBA::Boolean pd_pipe_full;
// On platforms that support pipes, after scanning a while with no
// activity, we poll / select with an infinite timeout to prevent
// unnecessary processing.
unsigned pd_idle_count;
#if defined(USE_POLL)
// On platforms where we use poll(), we maintain a pre-allocated
// array of pollfd structures and a parallel array of pointers to
// SocketHolders. pd_pollfd_n is the number of populated pollfds.
// pd_pollfd_len is the current length of both arrays.
struct pollfd* pd_pollfds;
SocketHolder** pd_pollsockets;
unsigned pd_pollfd_n;
unsigned pd_pollfd_len;
void growPollLists();
// Expand the pd_pollfds and pd_pollsockets to fit more values.
#elif defined(__WIN32__)
// Windows has select() but its fd_sets are more like pollfds, just
// less convenient...
omni_tracedcondition pd_select_cond; // timedwait on if nothing to select
fd_set pd_fd_set;
SocketHolder* pd_fd_sockets[FD_SETSIZE];
#else
// On other platforms we use select(). We maintain an fd_set and the
// highest socket number set in it plus 1.
fd_set pd_fd_set;
int pd_fd_set_n;
#endif
// Linked list of registered sockets.
SocketHolder* pd_collection;
CORBA::Boolean pd_changed;
friend class SocketHolder;
};
OMNI_NAMESPACE_END(omni)
#endif // __SOCKETCOLLECTION_H__
|