* Add "less" target to view make output through less.
[matthijs/ABM2.git] / ABM2 / Amaltheia / Network.h
1 /***************************************************************************
2  *   Copyright (C) 2005 by Dimitris Saougos & Filippos Papadopoulos   *
3  *   <psybases@gmail.com>                                                             *
4  *                                                                                                       *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU Library General Public License as       *
7  *   published by the Free Software Foundation; either version 2 of the    *
8  *   License, or (at your option) any later version.                                    *
9  *                                                                                                           *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU Library General Public     *
16  *   License along with this program; if not, write to the                 *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _NETWORK_H
22 #define _NETWORK_H
23
24 #include <netdb.h>
25 #include <sys/socket.h>
26 #include <netinet/in.h>
27 #include <arpa/inet.h>
28
29 #define AM_TCP  1
30 #define AM_UDP  2
31
32 extern char **argv;
33 extern int argc;
34
35 //group: Classes
36
37 /*class: Socket
38 A TCP/IP socket*/
39 class Socket
40 {
41 public:
42                 int s;
43
44 //group: Fields
45                 /*field: peer*/
46                 struct sockaddr_in peer;
47                 int type;
48
49 public:
50         //group: Constructors   
51         /*constructor: Socket
52 parameters:
53         sd -  a socket descriptor       */
54         Socket(int sd);
55         /*constructor: Socket
56         parameters:
57         type - can be *AM_TCP* or *AM_UDP*
58         protocol -  0
59         */
60         Socket(int type, int protocol);
61         ~Socket();
62
63 //group: Methods
64                 /*method: Bind */
65                 int Bind(int port);
66                 /*method: Listen */
67                 int Listen(int log);
68                 /*method: Accept */
69                 Socket * Accept(void);
70                 /*method: Connect */
71                 int Connect(void);
72                 /*method: Send */
73                 int Send(void *buffer, unsigned long size);
74                 /*method: Receive */
75                 int Receive(void *buffer, unsigned long size);
76                 /*method:  SendTo */
77                 int SendTo(void *buffer, unsigned long size);
78                 /*method: RecvFrom */
79                 int RecvFrom(void *buffer, unsigned long size);
80                 /*method: Select */
81                 int Select(unsigned long seconds, unsigned long microsecs);
82                 /*method: Select */
83                 int Select(unsigned long microsecs);
84                 /*method: SetPeer */
85                 void SetPeer(struct sockaddr_in data);
86                 /*method: GetPeer */
87                 struct sockaddr_in GetPeer(void);
88                 /*method: CreatePeer */
89                 struct sockaddr_in CreatePeer(const char *address, int port);
90
91 };
92
93
94 /*class: Network*/
95 class Network
96 {
97         public:
98                 bool ok;
99 //group: Constructors
100                 /*constructor: Network */
101                 Network();
102                 ~Network();
103 //group: Methods
104                 /*method: getSocket*/
105                 Socket * getSocket(int type, int protocol);
106 };
107
108
109 #endif