From ee937667fd0ecd82faab4c88d756b906fb625f1a Mon Sep 17 00:00:00 2001 From: sc Date: Tue, 28 Nov 2000 17:07:47 +0000 Subject: Integration into IvyLeague Uvh -> Ivl Multiplexer.* is renamed into Scheduler.* A few name conflicts in the merger with ex-DNN have been solved Imakefile is replaced by Makefile Created InetAddress.* and UnixAddress.* from Address.* Created IrdaAddress.* OLD/TextStream has been updated --- comm/Socket.cc | 70 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 36 deletions(-) (limited to 'comm/Socket.cc') diff --git a/comm/Socket.cc b/comm/Socket.cc index b90fe66..61244fa 100644 --- a/comm/Socket.cc +++ b/comm/Socket.cc @@ -10,6 +10,8 @@ * * $Id$ * $CurLog$ + * Removed Smart pointers + * Added ReuseAddress and AllowBroadcast */ #include "Socket.h" @@ -19,10 +21,9 @@ #include extern int errno; - -/*?class UchSocket -The class \typ{UchSocket} derives from \typ{UchChannel}. It is a -virtual base class: no objects of class \typ{UchSocket} are ever +/*?class IvlSocket +The class \typ{IvlSocket} derives from \typ{IvlChannel}. It is a +virtual base class: no objects of class \typ{IvlSocket} are ever created. It implements Unix sockets, that is file descriptors with two addresses: the address the socket is bound to, and the address it is connected to. An address needs to be bound to a socket only if @@ -31,7 +32,7 @@ connected to an address only for streams or connected datagrams. Thus, none of the addresses is mandatory. A socket can have potentially two addresses (the one it is BoundTo and -the one it is ConnectedTo. Once given to a socket, an \typ{UchAddress} +the one it is ConnectedTo. Once given to a socket, an \typ{IvlAddress} instance pointer is no more usable because it can be deleted and reallocated by the Socket when it is bound/connected. These address pointers are also deleted by the socket destructor. Thus, to know the @@ -48,8 +49,8 @@ always allocated by new. Theses addresses are deleted and reinstanciated after a \fun{Bind}. To obtain the addresses of a socket, use \fun{BoundTo} and \fun{ConnectedTo}. ?*/ -UchSocket :: UchSocket (UchAddress* bound, UchAddress* connected) -: UchChannel (), +IvlSocket :: IvlSocket (IvlAddress* bound, IvlAddress* connected) +: IvlChannel (), BAddr (bound), CAddr (connected), AddrFamily (AF_UNSPEC), @@ -58,8 +59,8 @@ UchSocket :: UchSocket (UchAddress* bound, UchAddress* connected) } /*?nodoc?*/ -UchSocket :: UchSocket (const UchSocket& s) -: UchChannel (s), +IvlSocket :: IvlSocket (const IvlSocket& s) +: IvlChannel (s), BAddr (s.BAddr), CAddr (s.CAddr), Ready (s.Ready) @@ -67,7 +68,7 @@ UchSocket :: UchSocket (const UchSocket& s) } /*?nodoc?*/ -UchSocket :: ~UchSocket () +IvlSocket :: ~IvlSocket () { if (BAddr) delete BAddr; if (CAddr) delete CAddr; @@ -80,14 +81,14 @@ one of \var{SOCK\_UNSPEC}, \var{SOCK\_STREAM}, \var{SOCK\_DGRAM}, depending on the class. ?*/ int -UchSocket :: SockType () +IvlSocket :: SockType () { } #endif /*?nextdoc?*/ void -UchSocket :: BindTo (UchAddress* a) +IvlSocket :: BindTo (IvlAddress* a) { if (BAddr) delete BAddr; @@ -98,7 +99,7 @@ UchSocket :: BindTo (UchAddress* a) Set the address a socket is to be bound to or connected to. ?*/ void -UchSocket :: ConnectTo (UchAddress* a) +IvlSocket :: ConnectTo (IvlAddress* a) { if (CAddr) delete CAddr; @@ -112,7 +113,7 @@ or its family must have been defined with \fun{SetFamily}. Return false if the family is undefined or if a system error occurred. ?*/ bool -UchSocket :: Open () +IvlSocket :: Open () { errno = 0; if (Fd >= 0) @@ -128,13 +129,13 @@ UchSocket :: Open () int fd = socket (AddrFamily, SockType (), 0); if (fd < 0) return false; - UchChannel::Open (fd); + IvlChannel::Open (fd); return true; } /*?nextdoc?*/ int -UchSocket :: Bind (UchAddress* addr) +IvlSocket :: Bind (IvlAddress* addr) { if (addr) BindTo (addr); @@ -148,10 +149,10 @@ UchSocket :: Bind (UchAddress* addr) return ret; GEN_ADDR naddr; - int alen = sizeof (naddr); + socklen_t alen = sizeof (naddr); if (getsockname (Fd, &naddr.sa, &alen) < 0) return -1; - BindTo (UchAddress::Decode (&naddr, alen)); + BindTo (IvlAddress::Decode (&naddr, alen)); return ret; } @@ -163,7 +164,7 @@ The returned value is that of the system call, unless opening failed in which ca -1 is returned. ?*/ int -UchSocket :: Connect (UchAddress* addr) +IvlSocket :: Connect (IvlAddress* addr) { if (addr) ConnectTo (addr); @@ -176,14 +177,13 @@ UchSocket :: Connect (UchAddress* addr) return ret; GEN_ADDR naddr; - int alen = sizeof (naddr); + socklen_t alen = sizeof (naddr); if (getpeername (Fd, &naddr.sa, &alen) < 0) return -1; - ConnectTo (UchAddress::Decode (&naddr, alen)); + ConnectTo (IvlAddress::Decode (&naddr, alen)); return ret; } - /*? Open the socket if it is not already open. Bind and connect it depending on the addresses that are defined. @@ -193,7 +193,7 @@ This function returns false if a system error occurred. In this case, the caller call \fun{SysError} to report the error. ?*/ bool -UchSocket :: Setup () +IvlSocket :: Setup () { if (! Open ()) return Ready = false; @@ -213,15 +213,14 @@ This function is intended for sockets that accept connections. It returns the file descriptor of the new connection, or -1 in case of failure. ?*/ int -UchSocket :: Accept () +IvlSocket :: Accept () { errno = 0; return accept (Fd, 0, 0); } - bool -UchSocket :: ReuseAddress (bool on) +IvlSocket :: ReuseAddress (bool on) { int parm = on; int res = setsockopt (Fd, SOL_SOCKET, SO_REUSEADDR, (char *)&parm, sizeof (parm)); @@ -229,19 +228,18 @@ UchSocket :: ReuseAddress (bool on) } bool -UchSocket :: AllowBroadcast (bool on) +IvlSocket :: AllowBroadcast (bool on) { int parm = on; int res = setsockopt (Fd, SOL_SOCKET, SO_BROADCAST, (char *)&parm, sizeof (parm)); return res < 0 ? false : true; } - /*?nodoc?*/ char* -UchSocket :: StrRepr (char* buf) +IvlSocket :: StrRepr (char* buf) { - UchChannel :: StrRepr (buf); + IvlChannel :: StrRepr (buf); strcat (buf, " / "); if (BAddr) BAddr->StrRepr (buf + strlen (buf)); @@ -259,7 +257,7 @@ UchSocket :: StrRepr (char* buf) /*?nextdoc?*/ int -UchSocket :: Family () +IvlSocket :: Family () { } /*? @@ -271,19 +269,19 @@ If an address is bound or connected to the socket, its family is used. Thus, an application seldom needs to call \fun{SetFamily}. ?*/ void -UchSocket :: SetFamily (int f) +IvlSocket :: SetFamily (int f) { } /*?nextdoc?*/ -UchAddress* -UchSocket :: BoundTo () +IvlAddress* +IvlSocket :: BoundTo () { } /*? Return the address currently bound or connected to the socket. ?*/ -UchAddress* -UchSocket :: ConnectedTo () +IvlAddress* +IvlSocket :: ConnectedTo () { } #endif /* DOC */ -- cgit v1.1