gameServer2/src/server/client.rs
changeset 12129 07972a8c2433
parent 12128 f50876f3eff8
child 12136 e25a82ce2374
--- a/gameServer2/src/server/client.rs	Mon Jan 02 00:16:22 2017 +0300
+++ b/gameServer2/src/server/client.rs	Tue Jan 03 00:19:47 2017 +0300
@@ -6,10 +6,11 @@
 use netbuf;
 
 use utils;
+use protocol::FrameDecoder;
 
 pub struct HWClient {
     sock: TcpStream,
-    buf_in: netbuf::Buf,
+    decoder: FrameDecoder,
     buf_out: netbuf::Buf
 }
 
@@ -17,7 +18,7 @@
     pub fn new(sock: TcpStream) -> HWClient {
         HWClient {
             sock: sock,
-            buf_in: netbuf::Buf::new(),
+            decoder: FrameDecoder::new(),
             buf_out: netbuf::Buf::new(),
         }
     }
@@ -43,8 +44,9 @@
     }
 
     pub fn readable(&mut self, poll: &Poll) -> io::Result<()> {
-        self.buf_in.read_from(&mut self.sock)?;
-        println!("Incoming buffer size: {}", self.buf_in.len());
+        let v = self.decoder.read_from(&mut self.sock)?;
+        self.decoder.extract_messages();
+        println!("Read {} bytes", v);
         Ok(())
     }