浏览代码

add more logging

tags/v0.1.0
Jeremy Latt 10 年前
父节点
当前提交
b8bbc7eeb5
共有 3 个文件被更改,包括 27 次插入6 次删除
  1. 15
    3
      irc/client.go
  2. 10
    1
      irc/net.go
  3. 2
    2
      irc/server.go

+ 15
- 3
irc/client.go 查看文件

@@ -15,6 +15,7 @@ type Client struct {
15 15
 	awayMessage string
16 16
 	channels    ChannelSet
17 17
 	conn        net.Conn
18
+	ctime       time.Time
18 19
 	destroyed   bool
19 20
 	hostname    string
20 21
 	idleTimer   *time.Timer
@@ -32,9 +33,12 @@ type Client struct {
32 33
 }
33 34
 
34 35
 func NewClient(server *Server, conn net.Conn) *Client {
36
+	now := time.Now()
35 37
 	client := &Client{
38
+		atime:    now,
36 39
 		channels: make(ChannelSet),
37 40
 		conn:     conn,
41
+		ctime:    now,
38 42
 		hostname: AddrLookupHostname(conn.RemoteAddr()),
39 43
 		replies:  make(chan Reply),
40 44
 		server:   server,
@@ -136,7 +140,7 @@ func (client *Client) writeConn() {
136 140
 
137 141
 	for reply := range client.replies {
138 142
 		if DEBUG_CLIENT {
139
-			log.Printf("%s ← %s %s", client, reply.Source(), reply)
143
+			log.Printf("%s ← %s", client, reply)
140 144
 		}
141 145
 		for _, str := range reply.Format(client) {
142 146
 			if DEBUG_NET {
@@ -161,6 +165,12 @@ func (client *Client) Destroy() {
161 165
 		return
162 166
 	}
163 167
 
168
+	if DEBUG_CLIENT {
169
+		log.Printf("%s destroy", client)
170
+	}
171
+
172
+	client.destroyed = true
173
+
164 174
 	client.conn.Close()
165 175
 
166 176
 	close(client.replies)
@@ -179,11 +189,13 @@ func (client *Client) Destroy() {
179 189
 
180 190
 	client.server.clients.Remove(client)
181 191
 
182
-	client.destroyed = true
183 192
 }
184 193
 
185 194
 func (client *Client) Reply(replies ...Reply) {
186
-	if client.replies == nil {
195
+	if client.destroyed {
196
+		if DEBUG_CLIENT {
197
+			log.Printf("%s.Reply: destroyed", client)
198
+		}
187 199
 		return
188 200
 	}
189 201
 	for _, reply := range replies {

+ 10
- 1
irc/net.go 查看文件

@@ -1,6 +1,7 @@
1 1
 package irc
2 2
 
3 3
 import (
4
+	"log"
4 5
 	"net"
5 6
 	"strings"
6 7
 )
@@ -19,9 +20,17 @@ func AddrLookupHostname(addr net.Addr) string {
19 20
 }
20 21
 
21 22
 func LookupHostname(addr string) string {
23
+	if DEBUG_NET {
24
+		log.Printf("LookupHostname(%s)", addr)
25
+	}
22 26
 	names, err := net.LookupAddr(addr)
23 27
 	if err != nil {
24 28
 		return addr
25 29
 	}
26
-	return strings.TrimSuffix(names[0], ".")
30
+
31
+	hostname := strings.TrimSuffix(names[0], ".")
32
+	if DEBUG_NET {
33
+		log.Printf("LookupHostname(%s) → %s", addr, hostname)
34
+	}
35
+	return hostname
27 36
 }

+ 2
- 2
irc/server.go 查看文件

@@ -52,7 +52,7 @@ func NewServer(config *Config) *Server {
52 52
 func (server *Server) receiveCommands(commands <-chan Command) {
53 53
 	for command := range commands {
54 54
 		if DEBUG_SERVER {
55
-			log.Printf("%s → %s %s", command.Client(), server, command)
55
+			log.Printf("%s → %s %+v", command.Client(), server, command)
56 56
 		}
57 57
 		client := command.Client()
58 58
 
@@ -65,7 +65,7 @@ func (server *Server) receiveCommands(commands <-chan Command) {
65 65
 		command.HandleServer(server)
66 66
 
67 67
 		if DEBUG_SERVER {
68
-			log.Printf("%s → %s %s processed", command.Client(), server, command)
68
+			log.Printf("%s → %s %+v processed", command.Client(), server, command)
69 69
 		}
70 70
 	}
71 71
 }

正在加载...
取消
保存