Skip to content

Commit

Permalink
Add option to close TCP connection after message
Browse files Browse the repository at this point in the history
  • Loading branch information
russss committed Jan 17, 2017
1 parent 5dd5adb commit 058f0f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion examples/irccat.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"tcp_listen": ":12345",
"tcp": {
"listen": ":12345",
"close_after_message": false
},
"http": {
"listen": ":8045",
"tls": false,
Expand Down
5 changes: 4 additions & 1 deletion tcplistener/tcplistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func New() (*TCPListener, error) {
var err error

listener := TCPListener{}
listener.socket, err = net.Listen("tcp", viper.GetString("tcp_listen"))
listener.socket, err = net.Listen("tcp", viper.GetString("tcp.listen"))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -57,6 +57,9 @@ func (l *TCPListener) handleConnection(conn net.Conn) {
log.Infof("[%s] message: %s", conn.RemoteAddr(), msg)
l.parseMessage(msg)
}
if viper.GetBool("tcp.close_after_message") {
conn.Close()
}
}
}

Expand Down

0 comments on commit 058f0f4

Please sign in to comment.