source: Sophya/trunk/AddOn/TAcq/swrapsock.h@ 3763

Last change on this file since 3763 was 3763, checked in by ansari, 15 years ago

Debug Ajout methodes Socket::SendAll(),ReceiveAll() , Reza 01/05/2010

File size: 2.8 KB
RevLine 
[3542]1#ifndef SWRAPSOCK_H
2#define SWRAPSOCK_H
3
4#include "machdefs.h"
5#include "pexceptions.h"
6
7#include <unistd.h>
8#include <iostream>
9
10#include <sys/types.h>
11#include <sys/socket.h>
12#include <netinet/in.h>
13
14
15namespace SOPHYA {
16
17/*!
18 \class SocketException
19 \ingroup SysTools
20 \brief Exception class used by IP socket wrapper classes in SysTools module
21*/
22
23class SocketException : public PException {
24 public:
25 explicit SocketException(const char * m) : PException(m) {}
26 explicit SocketException(const string& m) : PException(m) {}
27};
28
29
30// --------------------------
31// Classe de base pour enrober l'initialisation et l'utilisation
32// des sockets pour les connections IP.
33// --------------------------
34
35class Socket {
36public:
37 Socket(int s=-1);
[3757]38 Socket(Socket const & a);
[3542]39 ~Socket();
40
41 size_t Send(const char * buff, size_t len, int flag=0);
42 size_t Receive(char * buff, size_t len, int flag=0);
[3763]43 size_t SendAll(const char * buff, size_t len);
44 size_t ReceiveAll(char * buff, size_t len);
45
[3542]46 int Close();
[3757]47
48 inline Socket& operator=(Socket const & a)
49 { Set(a); return (*this); }
50
[3542]51 inline int SetPrtLevel(int lev=0)
52 { if (lev > 0) prtlev = lev; return prtlev; }
[3757]53 inline long NBytesSent() { return totsnd; }
54 inline long NBytesRecv() { return totrcv; }
55
56protected:
57 void Set(Socket const & a);
[3542]58
59 int skt;
60 long tstart; /* Temps de demarrage en sec */
61 long tlast; /* Temps de derniere acces en sec */
62 long totrcv; /* Nb total d'octets recus */
63 long totsnd; /* Nb total d'octets envoyes */
64 long dts; /* Dt en ms send (File or Data) */
65 long nbbs; /* Nb Octets send (File or Data) */
66 long dtr; /* Dt en ms recv (File or Data) */
67 long nbbr; /* Nb Octets recv (File or Data) */
68 long lstdt; /* Dt en ms last send or receive */
69 long lstnbb; /* Nb bytes last send or receive */
70 long errcnt; /* Total error count */
71 int prtlev;
72};
73
74
75// --------------------------
76// Classe ServerSocket - A instancier cote serveur
77// --------------------------
78
79class ServerSocket : public Socket
80{
81public :
82 ServerSocket(int port, int nconmax);
83 Socket WaitClientConnection();
84
85protected:
86 int portid;
87 struct sockaddr_in ipskt;
88 int NConMax;
89 int nclitot;
90};
91
92// --------------------------
93// Classe ClientSocket - A instancier cote client
94// --------------------------
95
96class ClientSocket : public Socket
97{
98public :
99 ClientSocket(string const& srvname, int port);
100 ClientSocket(const char* srvname, int port);
[3757]101 ClientSocket(ClientSocket const& a);
102 inline ClientSocket& operator=(ClientSocket const& a)
103 { SetC(a); return (*this); }
[3542]104protected:
[3757]105 void SetC(ClientSocket const& a);
[3542]106 void InitConnection(const char* srvname, int port);
[3757]107
[3542]108 int portid;
109 struct sockaddr_in ipskt;
110
111};
112
113} // Fin du namespace
114
115#endif
Note: See TracBrowser for help on using the repository browser.