2017-11-02 18:08:18 +03:00
|
|
|
// Copyright 2017 Joshua J Baker. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2017-07-04 06:39:18 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-11-03 04:31:36 +03:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2017-10-28 03:01:03 +03:00
|
|
|
"log"
|
2017-07-04 06:39:18 +03:00
|
|
|
|
2017-10-29 00:58:59 +03:00
|
|
|
"github.com/tidwall/evio"
|
2017-07-04 06:39:18 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-11-03 04:31:36 +03:00
|
|
|
var port int
|
|
|
|
flag.IntVar(&port, "port", 5000, "server port")
|
|
|
|
flag.Parse()
|
2017-10-28 03:01:03 +03:00
|
|
|
|
2017-11-03 04:31:36 +03:00
|
|
|
var events evio.Events
|
2017-11-06 13:58:06 +03:00
|
|
|
events.Serving = func(ctx evio.Context) (action evio.Action) {
|
2017-11-03 04:31:36 +03:00
|
|
|
log.Printf("echo server started on port %d", port)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
events.Opened = func(id int, addr evio.Addr) (out []byte, opts evio.Options, action evio.Action) {
|
|
|
|
//log.Printf("opened: %d: %s", id, addr.Remote.String())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
events.Closed = func(id int, err error) (action evio.Action) {
|
|
|
|
//log.Printf("closed: %d", id)
|
2017-10-28 03:01:03 +03:00
|
|
|
return
|
|
|
|
}
|
2017-10-29 00:58:59 +03:00
|
|
|
events.Data = func(id int, in []byte) (out []byte, action evio.Action) {
|
2017-10-28 03:01:03 +03:00
|
|
|
out = in
|
|
|
|
return
|
|
|
|
}
|
2017-11-03 04:31:36 +03:00
|
|
|
log.Fatal(evio.Serve(events, fmt.Sprintf("tcp://:%d", port)))
|
2017-07-04 06:39:18 +03:00
|
|
|
}
|