Browse Source

socket: Fixup sending code so we can support more connections

tags/v0.7.0
Daniel Oaks 7 years ago
parent
commit
c3be2d0d46
1 changed files with 19 additions and 5 deletions
  1. 19
    5
      irc/socket.go

+ 19
- 5
irc/socket.go View File

50
 // Close stops a Socket from being able to send/receive any more data.
50
 // Close stops a Socket from being able to send/receive any more data.
51
 func (socket *Socket) Close() {
51
 func (socket *Socket) Close() {
52
 	socket.Closed = true
52
 	socket.Closed = true
53
-	// socket will close once all data has been sent
53
+
54
+	// 'send data' to force close loop to happen
55
+	socket.linesToSendMutex.Lock()
56
+	socket.linesToSend = append(socket.linesToSend, "")
57
+	socket.linesToSendMutex.Unlock()
58
+	go socket.fillLineToSendExists()
54
 }
59
 }
55
 
60
 
56
 // CertFP returns the fingerprint of the certificate provided by the client.
61
 // CertFP returns the fingerprint of the certificate provided by the client.
155
 			}
160
 			}
156
 
161
 
157
 			// write data
162
 			// write data
158
-			_, err := socket.conn.Write([]byte(data))
159
-			if err != nil {
160
-				errOut = true
161
-				fmt.Println(err.Error())
163
+			if 0 < len(data) {
164
+				_, err := socket.conn.Write([]byte(data))
165
+				if err != nil {
166
+					errOut = true
167
+					fmt.Println(err.Error())
168
+					break
169
+				}
170
+			}
171
+
172
+			// check if we're closed
173
+			if socket.Closed {
174
+				socket.linesToSendMutex.Unlock()
162
 				break
175
 				break
163
 			}
176
 			}
177
+
164
 			socket.linesToSendMutex.Unlock()
178
 			socket.linesToSendMutex.Unlock()
165
 		}
179
 		}
166
 		if errOut {
180
 		if errOut {

Loading…
Cancel
Save