/usr/include/GNUstep/NGStreams/NGSocket.h is in libsope-dev 2.1.1-1.
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 | /*
Copyright (C) 2000-2005 SKYRIX Software AG
This file is part of SOPE.
SOPE 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, or (at your option) any
later version.
SOPE 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 SOPE; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#ifndef __NGNet_NGSocket_H__
#define __NGNet_NGSocket_H__
#import <Foundation/NSObject.h>
#include <NGStreams/NGSocketProtocols.h>
#if defined(WIN32)
# include <winsock.h>
#endif
@class NSFileHandle, NSException;
/*
Represents the sockets accessible through the standard Unix sockets library.
The socket class itself is abstract and has two concrete subclasses,
NGActiveSocket and NGPassiveSocket. The terminology may be confusing
at first, but I choose to use these instead of Client/ServerSocket
because the NGPassiveSocket accept method returns a socket which isn't
one of these. It's an active socket which is already connected.
NGActiveSocket represents a connection while NGPassiveSocket only accepts
connections (it can't be read or written).
Each socket has a local address. The socket can be bound to an address
by using the bind() call or the address can be assigned by the operating
system kernel.
Passive sockets are normally bound to a well-known port (or service),
active sockets receive in most cases their address from the kernel.
fd is the file descriptor gained through the socket() call. closeOnFree
specifies whether the socket is closed when the memory for the
socket object is reclaimed.
Note that the creation of the actual socket has to wait until it is
bound or a connect or listen call has been initiated. This is because
the socket() call needs the socket-domain, which is encapsulated in the
NGSocketAddress objects.
Until the socket is created the fd variable contains the value
NGInvalidSocketDescriptor.
*/
#if defined(WIN32)
# define NGInvalidSocketDescriptor INVALID_SOCKET
#else
# define NGInvalidSocketDescriptor ((int)-1)
#endif
@interface NGSocket : NSObject < NGSocket >
{
@protected
#if defined(WIN32)
SOCKET fd;
#else
int fd; // socket descriptor
#endif
id<NGSocketDomain> domain;
id<NGSocketAddress> localAddress;
NSFileHandle *fileHandle; // not retained !
struct {
int closeOnFree:1; // close socket on collect/dealloc ?
int isBound:1; // was a bind issued (either by the kernel or explicitly)
} flags;
NSException *lastException;
}
+ (id)socketInDomain:(id<NGSocketDomain>)_domain;
- (id)initWithDomain:(id<NGSocketDomain>)_domain; // designated initializer
// ************************* create a socket *****************
- (BOOL)primaryCreateSocket;
- (BOOL)close;
// ************************* bind a socket *******************
// throws
// NGSocketAlreadyBoundException if the socket is already bound
- (BOOL)bindToAddress:(id<NGSocketAddress>)_address;
// throws
// NGSocketAlreadyBoundException if the socket is already bound
- (BOOL)kernelBoundAddress;
// ************************* accessors ***********************
- (id<NGSocketAddress>)localAddress;
- (BOOL)isBound;
- (void)setLastException:(NSException *)_exception;
- (NSException *)lastException;
- (void)resetLastException;
- (int)socketType; // abstract
- (id<NGSocketDomain>)domain;
- (NSFileHandle *)fileHandle;
#if defined(WIN32)
- (SOCKET)fileDescriptor;
#else
- (int)fileDescriptor;
- (void)setFileDescriptor: (int) theFd;
#endif
// ************************* options *************************
//
// set methods throw NGCouldNotSetSocketOptionException
// get methods throw NGCouldNotGetSocketOptionException
- (void)setDebug:(BOOL)_flag;
- (void)setReuseAddress:(BOOL)_flag;
- (void)setKeepAlive:(BOOL)_flag;
- (void)setDontRoute:(BOOL)_flag;
- (BOOL)doesDebug;
- (BOOL)doesReuseAddress;
- (BOOL)doesKeepAlive;
- (BOOL)doesNotRoute;
- (void)setSendBufferSize:(int)_size;
- (void)setReceiveBufferSize:(int)_size;
- (int)sendBufferSize;
- (int)receiveBufferSize;
@end
#if defined(WIN32)
// Windows Descriptor Functions
// events
# ifndef POLLIN
# define POLLRDNORM 1
# define POLLIN POLLRDNORM
# define POLLWRNORM 2
# define POLLOUT POLLWRNORM
# define POLLERR 4
# define POLLHUP 4
# endif
/*
Polls a descriptor. Returns 1 if events occurred, 0 if a timeout occured
and -1 if an error other than EINTR or EAGAIN occured.
*/
int NGPollDescriptor(SOCKET _fd, short _events, int _timeout);
/*
Reading and writing with non-blocking IO support.
The functions return
-1 on error, with errno set to either recv's or poll's errno
0 on the end of file condition
-2 if the operation timed out
Enable login topic 'nonblock' to find out about timeouts.
*/
int NGDescriptorRecv(SOCKET _fd, char *_buf, int _len, int _flags, int _timeout);
int NGDescriptorSend(SOCKET _fd, const char *_buf, int _len, int _flags, int _timeout);
#endif /* WIN32 */
#endif /* __NGNet_NGSocket_H__ */
|