private void handleRequest(TcpClient tc, ref st_RequestHandle req, ILog lg, IHttpService service) { NetworkStream ns = tc.GetStream(); req.ns = ns; req.conn = tc; try { int nRead = 0; byte[] buf = req.bufIn; req.nRead = 0; try { nRead = ns.Read(buf, 0, st_RequestHandle.SZ_BUF_IN); req.nRead = nRead; } catch (Exception ex) { lg.log("TinyHttp.Read", ex); ns.Close(); tc.Close(); return; } object k = null; try { k = service.OnDispatch(ref req); ns.Flush(); } catch (Exception ex) { lg.log("TinyHttp.OnDispatch", ex); } try { service.OnServe(ref req, k); ns.Flush(); } catch (Exception ex) { lg.log("TinyHttp.OnServe", ex); } } finally { ns.Close(); tc.Close(); } }
public void OnServe(ref st_RequestHandle st, object objKey) { System.IO.Stream ns = st.ns; string s = Encoding.UTF8.GetString(st.bufIn, 0, st.nRead); using (StreamWriter wr = new StreamWriter(ns)) { ns.Write(buf_http_ok.buf, 0, buf_http_ok.len); ns.Flush(); wr.WriteLine("## echo Server ##"); wr.WriteLine(); wr.WriteLine(s); wr.Flush(); } }
public object OnDispatch(ref st_RequestHandle st) { return(""); }