aboutsummaryrefslogtreecommitdiffstats
path: root/src/ssl/tls_server.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-23 22:12:53 +0000
committerlloyd <[email protected]>2010-03-23 22:12:53 +0000
commit7479e66bb43e843c067e9a45145bafc84bdd41dc (patch)
treedcbd947508ab3bd8182816677d7d0d94edbf84c6 /src/ssl/tls_server.cpp
parent8fda37bf5b79bf6569e1e375c48e9d74171cb141 (diff)
Make Record_Reader event driven. Callers (eg TLS_Client and
TLS_Server) are not; they instead loop blocking on the socket. Will move the event-driven behavior upwards as I go.
Diffstat (limited to 'src/ssl/tls_server.cpp')
-rw-r--r--src/ssl/tls_server.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/ssl/tls_server.cpp b/src/ssl/tls_server.cpp
index 37d9dbcd1..8d33fca64 100644
--- a/src/ssl/tls_server.cpp
+++ b/src/ssl/tls_server.cpp
@@ -88,7 +88,8 @@ void server_check_state(Handshake_Type new_msg, Handshake_State* state)
TLS_Server::TLS_Server(RandomNumberGenerator& r,
Socket& sock, const X509_Certificate& cert,
const Private_Key& key, const TLS_Policy* pol) :
- rng(r), writer(sock), reader(sock), policy(pol ? pol : new TLS_Policy)
+ rng(r), peer(sock),
+ writer(sock), policy(pol ? pol : new TLS_Policy)
{
peer_id = sock.peer_id();
@@ -207,8 +208,26 @@ void TLS_Server::close(Alert_Level level, Alert_Type alert_code)
*/
void TLS_Server::state_machine()
{
- byte rec_type;
- SecureVector<byte> record = reader.get_record(rec_type);
+ byte rec_type = CONNECTION_CLOSED;
+ SecureVector<byte> record(1024);
+
+ u32bit bytes_needed = reader.get_record(rec_type, record);
+
+ while(bytes_needed)
+ {
+ u32bit to_get = std::min<u32bit>(record.size(), bytes_needed);
+ u32bit got = peer.read(&record[0], to_get);
+
+ if(got == 0)
+ {
+ rec_type = CONNECTION_CLOSED;
+ break;
+ }
+
+ reader.add_input(&record[0], got);
+
+ bytes_needed = reader.get_record(rec_type, record);
+ }
if(rec_type == CONNECTION_CLOSED)
{