Compare commits

..

No commits in common. "06e5e7cd9ce6ac5a79f51f4b9721c523d887e357" and "6e244be880fe28105b2e55cc52703eef7cd83381" have entirely different histories.

7 changed files with 65 additions and 79 deletions

View File

@ -4,7 +4,7 @@ import (
"fmt"
"time"
"git.qowevisa.me/qowevisa/tcpmachine/tcpclient"
"git.qowevisa.me/Qowevisa/tcpmachine/tcpclient"
)
func main() {

View File

@ -5,7 +5,7 @@ import (
"net"
"time"
"git.qowevisa.me/qowevisa/tcpmachine/tcpserver"
"git.qowevisa.me/Qowevisa/tcpmachine/tcpserver"
)
func main() {

2
go.mod
View File

@ -1,3 +1,3 @@
module git.qowevisa.me/qowevisa/tcpmachine
module git.qowevisa.me/Qowevisa/tcpmachine
go 1.20

View File

@ -8,9 +8,20 @@ import (
"net"
"strings"
"git.qowevisa.me/qowevisa/tcpmachine/tcpcommand"
"git.qowevisa.me/Qowevisa/tcpmachine/tcpcommand"
)
type ClientConfiguration struct {
MessageEndRune rune
MessageSplitRune rune
//
Status uint32
ErrorResolver func(chan error)
//
ServerHandlerFunc func(server net.Conn)
//
}
func GetDefaultConfig() *ClientConfiguration {
return &ClientConfiguration{
MessageEndRune: '\n',
@ -23,6 +34,26 @@ func GetDefaultConfig() *ClientConfiguration {
}
}
type ErrorResolverFunc func(errors chan error)
type Client struct {
MessageEndRune rune
MessageSplitRune rune
//
addr string
Status uint32
exit chan bool
Server net.Conn
IsConnected bool
//
ServerHandlerFunc func(server net.Conn)
//
ErrorsChannel chan error
ErrorResolver ErrorResolverFunc
//
Commands []tcpcommand.Command
}
func CreateClient(addr string, options ...ClientOption) *Client {
conf := GetDefaultConfig()

View File

@ -1,38 +0,0 @@
package tcpclient
import (
"net"
"git.qowevisa.me/qowevisa/tcpmachine/tcpcommand"
)
type ClientConfiguration struct {
MessageEndRune rune
MessageSplitRune rune
//
Status uint32
ErrorResolver func(chan error)
//
ServerHandlerFunc func(server net.Conn)
//
}
type ErrorResolverFunc func(errors chan error)
type Client struct {
MessageEndRune rune
MessageSplitRune rune
//
addr string
Status uint32
exit chan bool
Server net.Conn
IsConnected bool
//
ServerHandlerFunc func(server net.Conn)
//
ErrorsChannel chan error
ErrorResolver ErrorResolverFunc
//
Commands []tcpcommand.Command
}

View File

@ -9,9 +9,11 @@ import (
"net"
"strings"
"git.qowevisa.me/qowevisa/tcpmachine/tcpcommand"
"git.qowevisa.me/Qowevisa/tcpmachine/tcpcommand"
)
type ServerLoggingLevel int
const (
LogLevel_Nothing = 0
LogLevel_Connection = 1 << iota
@ -22,6 +24,15 @@ const (
LogLevel_ALL = LogLevel_Connection | LogLevel_Messages
)
type ServerConfiguration struct {
MessageEndRune rune
MessageSplitRune rune
HandleClientFunc func(client net.Conn)
LogLevel ServerLoggingLevel
//
ErrorResolver func(chan error)
}
func CreateHandleClientFuncFromCommands(bundle *tcpcommand.CommandBundle, conf ServerConfiguration) (func(client net.Conn), chan error) {
clientErrors := make(chan error, 16)
return func(client net.Conn) {
@ -47,6 +58,24 @@ func CreateHandleClientFuncFromCommands(bundle *tcpcommand.CommandBundle, conf S
}, clientErrors
}
type Server struct {
addr string
PreHandlerClientFunc func(client net.Conn)
HandleClientFunc func(client net.Conn)
// Use PostHandlerClientFunc in your HandleClientFunc if you
// use custom HandleClientFunc
PostHandlerClientFunc func(client net.Conn)
Exit chan bool
//
MessageEndRune rune
MessageSplitRune rune
ErrorsChannel chan error
ErrorResolver func(chan error)
LogLevel ServerLoggingLevel
//
Commands []tcpcommand.Command
}
func defaultHandleClientFunc(server *Server) func(net.Conn) {
return func(client net.Conn) {
if server.PostHandlerClientFunc != nil {

View File

@ -1,36 +0,0 @@
package tcpserver
import (
"net"
"git.qowevisa.me/qowevisa/tcpmachine/tcpcommand"
)
type ServerLoggingLevel int
type ServerConfiguration struct {
MessageEndRune rune
MessageSplitRune rune
HandleClientFunc func(client net.Conn)
LogLevel ServerLoggingLevel
//
ErrorResolver func(chan error)
}
type Server struct {
addr string
PreHandlerClientFunc func(client net.Conn)
HandleClientFunc func(client net.Conn)
// Use PostHandlerClientFunc in your HandleClientFunc if you
// use custom HandleClientFunc
PostHandlerClientFunc func(client net.Conn)
Exit chan bool
//
MessageEndRune rune
MessageSplitRune rune
ErrorsChannel chan error
ErrorResolver func(chan error)
LogLevel ServerLoggingLevel
//
Commands []tcpcommand.Command
}