nettobac  0.0.0
Network features for FreeBASIC code
nettobac.bi
Go to the documentation of this file.
1 /'* \file nettobac.bi
2 \brief Delarations for the \Proj classes
3 
4 This file contains the declarations for the classes, designed to handle
5 network client and server connections.
6 
7 Copyright (C) LGPLv2.1, see ReadMe.md for details.
8 
9 \since 0.0.0
10 '/
11 
12 #INCLUDE ONCE "nettobac_system.bi"
13 
14 
15 /'* \brief The connections class, providing `nPut` / `nGet`
16 
17 Do not create this class directly. It has to be constructed with a
18 nettobacServer::nOpen() or a nettobacClient::nOpen() call. Data can get
19 send or received to/from the peer with it.
20 
21 See section \ref SecErr_Connection for a list of possible error messages.
22 
23 \since 0.0.0
24 '/
25 TYPE n2bConnection
26 PUBLIC:
27  DECLARE CONSTRUCTOR(BYVAL AS LONG, BYVAL AS ZSTRING PTR PTR)
28  DECLARE DESTRUCTOR()
29  DECLARE FUNCTION nPut OVERLOAD(BYVAL AS STRING, BYVAL AS USHORT = 100) AS INTEGER
30  DECLARE FUNCTION nPut(BYVAL AS ANY PTR, BYVAL AS INTEGER, BYVAL AS USHORT = 100) AS INTEGER
31  DECLARE FUNCTION nGet(BYREF AS STRING, BYVAL AS USHORT = 100) AS CONST ZSTRING CONST PTR
32  AS ZSTRING PTR PTR Errr
33 PROTECTED:
34  AS LONG _
35  Sock '*< The socket number
36  AS fd_set _
37  FdsR _ '*< File descriptor for read
38  , FdsW '*< File descriptor for write
39  AS timeval _
40  Timeout '*< How long should we wait until network is ready
41 END TYPE
42 '& typedef n2bConnection* n2bConnection_PTR;
43 
44 
45 '
46 /'* \brief Utility class to handle n2bConnection pointers, providing `nClose`
47 
48 The base class of the \Proj instances. It manages the connection
49 instances and provides the methods to open connections, to collects
50 their pointers in the array n2bFactory::Slots and to close a connection
51 manualy. The destructor closes all remaining connections.
52 
53 See section \ref SecErr_Factory for a list of possible error messages.
54 
55 \since 0.0.0
56 '/
57 TYPE n2bFactory EXTENDS OBJECT
58 PUBLIC:
59  AS ZSTRING PTR Errr '*< The common error message (`NULL` in case of no error)
60  /'* \brief The array to store open connections
61 
62  In case of a server instance use this array to scan over all open
63  connections. See function #doServer() for an example.
64 
65  '/
66  AS n2bConnection PTR Slots(ANY)
67  DECLARE CONSTRUCTOR()
68  DECLARE VIRTUAL DESTRUCTOR()
69  DECLARE ABSTRACT FUNCTION nOpen() AS n2bConnection PTR
70  DECLARE FUNCTION nClose(BYVAL AS n2bConnection PTR) AS CONST ZSTRING CONST PTR
71 PROTECTED:
72  AS LONG Sock '*< The socket to use
73  DECLARE FUNCTION slot(BYVAL AS LONG) AS n2bConnection PTR
74 END TYPE
75 
76 
77 /'* \brief The client class, providing `nOpen`
78 
79 This class is an instance to act as a client. This is
80 
81 - connecting to a server
82 - sending data requests
83 - receiving returned data
84 
85 See section \ref SecErr_Client for a list of possible error messages.
86 
87 \since 0.0.0
88 '/
89 TYPE nettobacClient EXTENDS n2bFactory
90 PUBLIC:
91  DECLARE CONSTRUCTOR(BYREF AS STRING, BYVAL AS USHORT = 80)
92  DECLARE VIRTUAL FUNCTION nOpen() AS n2bConnection PTR
93 END TYPE
94 
95 
96 /'* \brief The server class, providing `nOpen`
97 
98 This class is an instance to act as a server. This is
99 
100 - listening to a port
101 - accepting client connection requests
102 - receiving data requests
103 - sending data
104 
105 See section \ref SecErr_Server for a list of possible error messages.
106 
107 \since 0.0.0
108 '/
109 TYPE nettobacServer EXTENDS n2bFactory
110 PUBLIC:
111  DECLARE CONSTRUCTOR(BYVAL AS USHORT = 80, BYVAL AS INTEGER = 64)
112  DECLARE VIRTUAL FUNCTION nOpen() AS n2bConnection PTR
113 PROTECTED:
114  AS timeval Timeout '*< The timeout value to abort slow or impossible transmissions
115 END TYPE
116