summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/socket/socket_text.hh
blob: b734753ff38fabd36970e51089e05395064fee72 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef socket_text_hh
#define socket_text_hh
// socket_text.hh
// robert - programme du robot 2005. {{{
//
// Copyright (C) 2005 Dufour J�r�my
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// Contact :
//        Web: %WEB%
//      Email: <dufourj@efrei.fr>
// }}}

class ServerSocket;
class Address;
#include "data/data_buffer.hh"

#include <vector>

class SocketText {
    /// Structure pour stocker les informations d'un message.
    typedef struct {
	unsigned int size;
	DataBuffer::dataType_e type;
    } mess_t;
    std::vector <mess_t> messList_;
    /// L'identificateur du socket.
    int socket_;
    /// Buffer pour le header.
    std::vector<char> headBuf_;
    /// Buffer de reception de donn�es.
    std::vector<char> recvBuf_;
    /// Buffer d'�mission de donn�es.
    std::vector<char> sendBuf_;
    /// Taille des buffers d'E/S XXX
    unsigned int recvBufPos_;
    unsigned int bufferOldSize_;
    unsigned int bufferCurSize_;
    /// Nombre de message dans le buffer
    int numMessageBuffer_;
    DataBuffer::dataType_e type_;
    /// Encodage du message (rajout du header)
    void encode (const char *data, const int size,
		const DataBuffer::dataType_e type);
    /// D�codage du header.
    int decode (void);

  public:
    /// Constructeur du serveur.
    SocketText (ServerSocket &ss);
    /// Constructeur du serveur avec addresse.
    SocketText (ServerSocket &ss, Address &a);
    /// Constructeur du client.
    SocketText (const Address &a);
    /// Envoie d'un buffer de donn�es.
    SocketText &operator<< (const DataBuffer &d);
    /// Reception d'un buffer de donn�es.
    SocketText &operator>> (DataBuffer &d);
    /// Envoie des donn�es du buffer.
    int send (void);
    /// Reception de donn�es dans un vecteur.
    bool recv (void);
    /// Changement du bloquant non/bloquant.
    void nonblock (bool flag = true);
};

#endif // socket_text_hh