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

.

parent fddbe14c
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
neo "../.." neo "../.."
"fmt" "fmt"
"context" "context"
"time" _ "time"
) )
...@@ -17,18 +17,20 @@ import ( ...@@ -17,18 +17,20 @@ import (
// cluster, masterv, bind ... // cluster, masterv, bind ...
func main() { func main() {
var t neo.Tid = neo.MAX_TID // var t neo.Tid = neo.MAX_TID
fmt.Printf("%T %x\n", t, t) // fmt.Printf("%T %x\n", t, t)
println("TODO") // println("TODO")
storsrv := &neo.StorageApplication{} storsrv := &neo.StorageApplication{}
/*
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
go func() { go func() {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
cancel() cancel()
}() }()
//ctx := context.Background() */
ctx := context.Background()
err := neo.ListenAndServe(ctx, "tcp", "localhost:1234", storsrv) err := neo.ListenAndServe(ctx, "tcp", "localhost:1234", storsrv)
fmt.Println(err) fmt.Println(err)
......
...@@ -16,8 +16,17 @@ type StorageApplication struct { ...@@ -16,8 +16,17 @@ type StorageApplication struct {
func (stor *StorageApplication) ServeConn(ctx context.Context, conn net.Conn) { func (stor *StorageApplication) ServeConn(ctx context.Context, conn net.Conn) {
fmt.Printf("stor: serving new client %s <-> %s\n", conn.LocalAddr(), conn.RemoteAddr()) 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 //fmt.Fprintf(conn, "Hello up there, you address is %s\n", conn.RemoteAddr()) // XXX err
conn.Close() // 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 { ...@@ -31,8 +40,6 @@ type Server interface {
ServeConn(ctx context.Context, conn net.Conn) // XXX error ? ServeConn(ctx context.Context, conn net.Conn) // XXX error ?
} }
// srv.ServeConn(ctx context.Context, conn net.Conn)
// Run service on a listener // Run service on a listener
// - accept incoming connection on the listener // - accept incoming connection on the listener
// - for every accepted connection spawn srv.ServeConn() in separate goroutine. // - 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 { ...@@ -71,8 +78,7 @@ func Serve(ctx context.Context, l net.Listener, srv Server) error {
// TODO text // TODO text
// XXX move -> generic place ? // XXX move -> generic place ?
// XXX get (net, laddr) from srv ? // XXX split -> separate Listen() & Serve()
// XXX split -> separate Listen()
func ListenAndServe(ctx context.Context, net_, laddr string, srv Server) error { func ListenAndServe(ctx context.Context, net_, laddr string, srv Server) error {
l, err := net.Listen(net_, laddr) l, err := net.Listen(net_, laddr)
if err != nil { 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