File: socket.h

package info (click to toggle)
sms-pl 1.9.2m-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 620 kB
  • ctags: 355
  • sloc: cpp: 2,143; ansic: 1,046; perl: 272; makefile: 113; sh: 97
file content (65 lines) | stat: -rw-r--r-- 1,664 bytes parent folder | download | duplicates (2)
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
#ifndef __socket_h
#define __socket_h

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
 
const int MAX_MSG_LEN = 16384;

class Socket
{
 protected:
     int sock, status, port;
     char *hostname;

     int virtual connect_socket();
     int bind_socket();
 public:
     typedef int AvailType;
     enum Avail_Type { SCK_READ, SCK_WRITE, SCK_EXC };

     Socket(int _sock = 0) : sock(_sock),hostname(NULL),port(-1) {};
     Socket(const char *_hostname, int _port);
     ~Socket();
     int Ok();
     int MsgAvail(AvailType mode);

     int Sock() const { return sock; };
     
     int WriteMsg(const char *fmt, ...);
     int WriteMsg(const void *buf, int buf_len);

     // odczytuje wiadomosc z gniazdka - znakiem konca bedzie takze znak
     // nowej linii '\n'
     char *ReadMsg(int max_len = MAX_MSG_LEN);
     // jesli buf_len == -1 to odczyta wszystko z gniazdka, jesli nie to 
     // tyle ile bylo w buf_len. znaczenie buf takie jak ponizej
     char *ReadAll(int &buf_len);

     // zwroci odczytany bufor danych, jesli buf!=NULL to odczyta dane do 
     // niego, jesli buf==NULL to zaalokuje nowy bufor o wielkosci buf_len lub
     // MAX_MSG_LEN gdy buf_len<=0, w buf_len zwroci ilosc odczytanych bajtow
     // w przypadku bledu zwroci NULL i buf_len=-1
     void *ReadMsg(void *buf, int &buf_len);
     int ReadMsg(int buf_len, void *buf);

};

#ifndef NO_ANYIP

class AnyIPSocket : public Socket {
protected:
	char *srcip;

	int virtual connect_socket();
	int bindaddr_socket (struct addrinfo * ai_bptr);

public:
	AnyIPSocket(const char *_hostname, int _port,char * srcip);
};

#endif // NO_ANYIP

#endif