Commit e8954823 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 2998b840
......@@ -6,6 +6,8 @@ package main
import (
_ "../../storage" // XXX rel ok?
neo "../.."
"fmt"
)
......@@ -13,6 +15,7 @@ import (
// cluster, masterv, bind ...
func main() {
// TODO
var t neo.Tid = neo.MAX_TID
fmt.Printf("%T %x\n", t, t)
println("TODO")
}
// XXX license
// TODO copyright / license
// ZODB types
package neo // XXX -> zodb ?
// Package neo implements distributed object storage for ZODB
// TODO text
package neo
// ZODB types
// XXX naming -> TID, OID ?
type Tid uint64 // XXX or [8]byte ?
type Oid uint64 // XXX or [8]byte ?
type Tid uint64 // transaction identifier TODO encode as BE
type Oid uint64 // object identifier TODO encode as BE
/*
// XXX "extended" oid - oid + serial, completely specifying object revision
type Xid struct {
Tid
Oid
}
*/
const (
//INVALID_UUID UUID = 0
INVALID_TID Tid = 1<<64 - 1 // 0xffffffffffffffff TODO recheck it is the same
INVALID_OID Oid = 0xffffffffffffffff // 1<<64 - 1
ZERO_TID Tid = 0 // XXX or simply TID{} ? // XXX -> TID0 ?
INVALID_TID Tid = 1<<64 - 1 // 0xffffffffffffffff
INVALID_OID Oid = 1<<64 - 1
ZERO_TID Tid = 0 // XXX or simply TID{} ?
TID0 Tid = ZERO_TID // XXX ^^^ choose 1
ZERO_OID Oid = 0 // XXX or simply OID{} ? // XXX -> OID0
// OID_LEN = 8
// TID_LEN = 8
MAX_TID Tid = 0x7fffffffffffffff // SQLite does not accept numbers above 2^63-1 // XXX -> TIDMAX ?
MAX_TID Tid = 1<<63 - 1 // 0x7fffffffffffffff
// SQLite does not accept numbers above 2^63-1
// ZODB also defines maxtid to be max signed int64 since baee84a6 (Jun 7 2016)
TIDMAX Tid = MAX_TID // XXX ^^^ choose 1
)
......
// TODO copyright / license
package neo
import (
"context"
)
// NEO Storage application
type StorageApplication struct {
}
// ----------------------------------------
// Server is an interface that represents networked server XXX text
type Server interface {
// ServeConn serves already established connection in a blocking way.
// ServeConn is usually run in separate goroutine XXX text
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.
//
// the listener is closed when Serve returns.
// XXX text
// XXX move -> generic place ?
func Serve(ctx context.Context, l net.Listener, srv Server) error {
// close listener when either cancelling or returning (e.g. due to an error)
// ( when cancelling - listener close will signal to all accepts to
// terminate with an error )
retch := make(chan struct{})
defer func() { close(retch) }()
go func(
select {
case <-ctx.Done():
case <-retch:
}
l.Close() // XXX err
)()
// main Accept -> ServeConn loop
for {
conn, err := l.Accept()
if err != nil {
// TODO check done channel of l/srv somehow
// TODO err -> net.Error && .Temporary() -> some throttling
return err
}
go srv.ServeConn(ctx, conn)
}
}
// TODO text
// XXX move -> generic place ?
// XXX get (net, laddr) from srv ?
// XXX split -> separate Listen()
func ListenAndServe(ctx context.Context, net, laddr string, srv Server) error {
l, err := net.Listen(net, laddr)
if err != nil {
return err
}
// TODO set keepalive on l
// TODO if TLS config -> tls.NewListener()
return Serve(ctx, l, srv)
}
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