Commit 8c564e42 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent fddbe14c
......@@ -9,7 +9,7 @@ import (
neo "../.."
"fmt"
"context"
"time"
_ "time"
)
......@@ -17,18 +17,20 @@ import (
// cluster, masterv, bind ...
func main() {
var t neo.Tid = neo.MAX_TID
fmt.Printf("%T %x\n", t, t)
println("TODO")
// var t neo.Tid = neo.MAX_TID
// fmt.Printf("%T %x\n", t, t)
// println("TODO")
storsrv := &neo.StorageApplication{}
/*
ctx, cancel := context.WithCancel(context.Background())
go func() {
time.Sleep(5 * time.Second)
cancel()
}()
//ctx := context.Background()
*/
ctx := context.Background()
err := neo.ListenAndServe(ctx, "tcp", "localhost:1234", storsrv)
fmt.Println(err)
......
......@@ -16,8 +16,17 @@ type StorageApplication struct {
func (stor *StorageApplication) ServeConn(ctx context.Context, conn net.Conn) {
fmt.Printf("stor: serving new client %s <-> %s\n", conn.LocalAddr(), conn.RemoteAddr())
fmt.Fprintf(conn, "Hello up there, you address is %s\n", conn.RemoteAddr()) // XXX err
conn.Close() // XXX err
//fmt.Fprintf(conn, "Hello up there, you address is %s\n", conn.RemoteAddr()) // XXX err
//conn.Close() // XXX err
// TODO read PktHeader (fixed length) (-> length, PktType (by .code))
// TODO PktHeader
rxbuf := bytes.Buffer{}
rxl := io.LimitedReader{R: conn, N: PktHeadLen}
// read first pkt chunk: header + some data (all in 1 read call)
rxl.N = 4096
n, err := rxbuf.ReadFrom(rxl)
}
......@@ -31,8 +40,6 @@ type Server interface {
ServeConn(ctx context.Context, conn net.Conn) // XXX error ?
}
// srv.ServeConn(ctx context.Context, conn net.Conn)
// Run service on a listener
// - accept incoming connection on the listener
// - for every accepted connection spawn srv.ServeConn() in separate goroutine.
......@@ -71,8 +78,7 @@ func Serve(ctx context.Context, l net.Listener, srv Server) error {
// TODO text
// XXX move -> generic place ?
// XXX get (net, laddr) from srv ?
// XXX split -> separate Listen()
// XXX split -> separate Listen() & Serve()
func ListenAndServe(ctx context.Context, net_, laddr string, srv Server) error {
l, err := net.Listen(net_, laddr)
if err != nil {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment