summaryrefslogtreecommitdiff
path: root/comm/Socket.h
blob: dfd291d6c1d7fb6b37448801a9793e3898bbb351 (plain)
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
/*
 *	Ivy League
 *
 *	Sockets
 *
 *	Copyright 1990-2000
 *	Laboratoire de Recherche en Informatique (LRI)
 *	Centre d'Etudes de la Navigation Aerienne (CENA)
 *
 *	original code by Michel Beaudouin-Lafon,
 *	modified by Stephane Chatty and Stephane Sire
 *
 *	$Id$
 *
 */

#ifndef Socket_H_
#define Socket_H_

#include "cplus_bugs.h"
#include "Channel.h"
#include "Address.h"

extern char* StrReprBuf;

#define SOCK_UNSPEC	0

//	Virtual base class for sockets.
//	A socket is a channel and an address.
//	As a channel, it is immutable, and must be initialized once and for all at creation.
//
class IvlSocket : public IvlChannel {
protected:
	IvlAddress*	BAddr;
	IvlAddress*	CAddr;
	int		AddrFamily;
	bool		Ready;

/*?public?*/
		IvlSocket (IvlAddress*, IvlAddress*);
		IvlSocket (const IvlSocket& s);
		~IvlSocket ();

public:
	
virtual	int		SockType () = 0;
inline	int		Family ()			{ return AddrFamily; }
inline	void		SetFamily (int f)		{ AddrFamily = f; }
inline	bool		IsReady () const		{ return Ready; }
	void		BindTo (IvlAddress*);
	void		ConnectTo (IvlAddress*);
inline	IvlAddress*	BoundTo ()		{ return BAddr; }
inline	IvlAddress*	ConnectedTo ()		{ return CAddr; }
	bool		Open ();
	int		Bind (IvlAddress* = 0);
	int		Connect (IvlAddress* = 0);
	int		Accept ();
	bool		Setup ();
	bool		ReuseAddress (bool = true);
	bool		AllowBroadcast (bool = true);
	char*		StrRepr (char* = StrReprBuf);
};

#endif /* Socket_H_ */