X-Git-Url: http://www.git.cypherpunks.ru/?p=goircd.git;a=blobdiff_plain;f=client.go;h=07a209b61d0a524653e56714bfa7fe81b10e4ebf;hp=f9f79569c621d327269941e669ff3b2598b6f0bd;hb=def74ddc09249de9ab72001bb00550863d7f27e6;hpb=80082ba6f68530a3806705c6313abdc8cbb799d8 diff --git a/client.go b/client.go index f9f7956..07a209b 100644 --- a/client.go +++ b/client.go @@ -34,13 +34,16 @@ type Client struct { hostname string conn net.Conn registered bool - ping_sent bool - timestamp time.Time nickname string username string realname string } +type ClientAlivenessState struct { + ping_sent bool + timestamp time.Time +} + func (client Client) String() string { return client.nickname + "!" + client.username + "@" + client.conn.RemoteAddr().String() } @@ -52,10 +55,10 @@ func NewClient(hostname string, conn net.Conn) *Client { // Client processor blockingly reads everything remote client sends, // splits messages by CRLF and send them to Daemon gorouting for processing // it futher. Also it can signalize that client is unavailable (disconnected). -func (client *Client) Processor(sink chan ClientEvent) { +func (client *Client) Processor(sink chan<- ClientEvent) { var buf_net []byte buf := make([]byte, 0) - log.Println("New client", client) + log.Println(client, "New client") sink <- ClientEvent{client, EVENT_NEW, ""} for { buf_net = make([]byte, BUF_SIZE) @@ -65,8 +68,6 @@ func (client *Client) Processor(sink chan ClientEvent) { sink <- ClientEvent{client, EVENT_DEL, ""} break } - client.timestamp = time.Now() - client.ping_sent = false buf_net = bytes.TrimRight(buf_net, "\x00") buf = append(buf, buf_net...) if !bytes.HasSuffix(buf, []byte(CRLF)) {