1 #include "http_connection.h" 15 _writer.reserve(102400);
19 HttpConnection::~HttpConnection(
void)
30 int HttpConnection::DoReadHeader(
char * message,
int buffersize,
Time_Clock ¤tTime)
32 int ans = _Reader.PumpHTTPHeaderRead(message,buffersize,*
this);
37 _headerDetail.assign(message,buffersize);
42 if(_Timer.Expired(currentTime) ==
true)
50 int HttpConnection::DoReadBody(
char * message1,
int buffersize,
Time_Clock ¤tTime)
52 int ans = _Reader.PumpSizeRead(_bodyDetail,*
this);
60 if(_Timer.Expired(currentTime) ==
true)
66 _state = WAITING_TO_FINALIZE;
71 int HttpConnection::ReadIt(
char * message,
int buffersize,
Time_Clock ¤tTime)
76 return DoReadHeader(message, buffersize,currentTime);
80 return DoReadBody(message, buffersize,currentTime);
83 case(WAITING_TO_FINALIZE):
84 return TryAndFinalize();
88 return CloseStateWriter(currentTime);
94 return ConnectionDoClose;
98 CloseState HttpConnection::ProcessMessage(
char * message,
Time_Clock ¤tTime)
100 if(_state == READING_POST )
102 _state = WAITING_TO_FINALIZE;
103 return ConnectionDoClose;
107 if(_parser.ParseThis(message) !=
true)
110 return ConnectionDoClose;
115 if(_parser.GetRequestType() ==
"POST")
117 int context_length = _parser.getContentLength();
118 if(context_length > 0)
121 _state = READING_POST;
122 _bodyDetail.SetDataSize(context_length);
123 return ConnectionDoNotClose;
127 _state = WAITING_TO_FINALIZE;
129 _parser.SetBodyText(_bodyDetail);
130 _Timer.ResetTime(currentTime);
132 if(BuildPage(_writer,_parser) !=
true)
133 return ConnectionDoClose;
135 if(_state == WRITING_DATA)
137 if(CloseStateWriter(currentTime) <0)
138 return ConnectionDoClose;
141 return ConnectionDoNotClose;
145 int HttpConnection::CloseStateWriter(
Time_Clock ¤tTime)
147 int fans = _writer.Flush(*
this);
151 if(_writer.AmountBuffered() <= 0)
154 if(_Timer.Expired(currentTime) ==
true)
161 void HttpConnection::Reset()
165 _Timer.ForceToExpired();
A simple place to store and munipulate tcp and port address for communication layer.
TypeHandle is the identifier used to differentiate C++ class types.