Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vsnet_sockethttp.h
Go to the documentation of this file.
1 #ifndef VSNET_SOCKET_HTTP_H
2 #define VSNET_SOCKET_HTTP_H
3 
4 #include <config.h>
5 
6 #include <sys/types.h>
7 
8 #include "vsnet_socketbase.h"
9 #include "vsnet_sockettcp.h"
10 
11 typedef unsigned char u_int8_t;
12 typedef unsigned int u_int32_t;
13 
14 /***********************************************************************
15 * VsnetTCPSocket - declaration
16 ***********************************************************************/
17 
18 class VsnetHTTPSocket : public VsnetSocketBase //VsnetTCPSocket
19 {
20 //I would like an entire VsnetTCPSocket, but that requires that data is VS packet format, which HTTP is not.
21  std::string _path;
22  std::string _hostheader;
23  std::map< std::string, std::string >_header;
24  std::string _incompleteheader;
25  int _incompleteheadersection;
26  int _content_length;
27  bool _send_more_data; //Has the server allowed keep-alive?
28 
29  std::list< std::string >dataToSend;
30  int sendDataPos;
31  std::string dataToReceive;
32  AddressIP _remote_ip;
33  std::string waitingToReceive;
34  int numRetries;
35  bool readHeader;
36  bool parseHeaderByte( char rcvchr );
37  bool ischunked;
38  int timeToNextRequest; //Wait a second between requests.
39  bool readingchunked;
40  int chunkedlen;
41  char chunkedchar;
42 public: VsnetHTTPSocket( const AddressIP &remote_ip, const std::string &host, const std::string &path, SocketSet &set );
43  VsnetHTTPSocket( const std::string &url, SocketSet &set );
44 
45  virtual bool lower_selected( int datalen = -1 );
46  virtual int lower_sendbuf();
47  virtual void lower_clean_sendbuf();
48  friend std::ostream&operator<<( std::ostream &ostr, const VsnetHTTPSocket &s );
49 
50  bool sendstr( const std::string &data );
51  bool recvstr( std::string &data );
52  virtual bool need_test_writable();
53  virtual bool write_on_negative();
54  virtual int optPayloadSize() const
55  {
56  return 500;
57  }
58 
59  virtual bool isActive();
60  void resendData();
61  void reopenConnection();
62  virtual bool isReadyToSend( fd_set* );
63  virtual void dump( std::ostream &ostr ) const;
64 };
65 
66 std::ostream&operator<<( std::ostream &ostr, const VsnetHTTPSocket &s );
67 #endif
68