Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
fddbe14c
Commit
fddbe14c
authored
Nov 25, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
e8954823
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
5 deletions
+30
-5
t/neo/cmd/neostorage-go/neostorage.go
t/neo/cmd/neostorage-go/neostorage.go
+14
-0
t/neo/storage.go
t/neo/storage.go
+16
-5
No files found.
t/neo/cmd/neostorage-go/neostorage.go
View file @
fddbe14c
...
...
@@ -8,6 +8,8 @@ import (
_
"../../storage"
// XXX rel ok?
neo
"../.."
"fmt"
"context"
"time"
)
...
...
@@ -18,4 +20,16 @@ func main() {
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()
err
:=
neo
.
ListenAndServe
(
ctx
,
"tcp"
,
"localhost:1234"
,
storsrv
)
fmt
.
Println
(
err
)
}
t/neo/storage.go
View file @
fddbe14c
...
...
@@ -4,13 +4,22 @@ package neo
import
(
"context"
"net"
"fmt"
)
// NEO Storage application
// XXX naming
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
}
// ----------------------------------------
...
...
@@ -32,24 +41,26 @@ type Server interface {
// XXX text
// XXX move -> generic place ?
func
Serve
(
ctx
context
.
Context
,
l
net
.
Listener
,
srv
Server
)
error
{
fmt
.
Printf
(
"stor: serving on %s ...
\n
"
,
l
.
Addr
())
// 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
(
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 == closed <-> ctx was cancelled
// TODO err -> net.Error && .Temporary() -> some throttling
return
err
}
...
...
@@ -62,8 +73,8 @@ func Serve(ctx context.Context, l net.Listener, srv Server) error {
// 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
)
func
ListenAndServe
(
ctx
context
.
Context
,
net
_
,
laddr
string
,
srv
Server
)
error
{
l
,
err
:=
net
.
Listen
(
net
_
,
laddr
)
if
err
!=
nil
{
return
err
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment