3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

don't wait for writing to complete

This commit is contained in:
Jeremy Latt 2014-02-20 11:15:42 -08:00
parent 9960089226
commit c0dc733351
3 changed files with 20 additions and 16 deletions

View File

@ -17,7 +17,6 @@ type Client struct {
awayMessage string
channels ChannelSet
ctime time.Time
doneWriting chan bool
flags map[UserMode]bool
hasQuit bool
hops uint
@ -37,16 +36,15 @@ type Client struct {
func NewClient(server *Server, conn net.Conn) *Client {
now := time.Now()
client := &Client{
atime: now,
channels: make(ChannelSet),
ctime: now,
doneWriting: make(chan bool),
flags: make(map[UserMode]bool),
hostname: AddrLookupHostname(conn.RemoteAddr()),
phase: server.InitPhase(),
server: server,
socket: NewSocket(conn),
replies: make(chan string),
atime: now,
channels: make(ChannelSet),
ctime: now,
flags: make(map[UserMode]bool),
hostname: AddrLookupHostname(conn.RemoteAddr()),
phase: server.InitPhase(),
server: server,
socket: NewSocket(conn),
replies: make(chan string, 16),
}
client.loginTimer = time.AfterFunc(LOGIN_TIMEOUT, client.connectionTimeout)
@ -97,10 +95,11 @@ func (client *Client) connectionClosed() {
func (client *Client) writeReplies() {
for reply := range client.replies {
client.socket.Write(reply)
if client.socket.Write(reply) != nil {
break
}
}
client.socket.Close()
client.doneWriting <- true
}
//
@ -163,7 +162,7 @@ func (client *Client) destroy() {
// clean up self
close(client.replies)
<-client.doneWriting
client.loginTimer.Stop()
if client.idleTimer != nil {

View File

@ -10,14 +10,14 @@ func NewStringReply(source Identifier, code StringCode,
format string, args ...interface{}) string {
header := fmt.Sprintf(":%s %s ", source, code)
message := fmt.Sprintf(format, args...)
return header + message + CRLF
return header + message
}
func NewNumericReply(target *Client, code NumericCode,
format string, args ...interface{}) string {
header := fmt.Sprintf(":%s %s %s ", target.server.Id(), code, target.Nick())
message := fmt.Sprintf(format, args...)
return header + message + CRLF
return header + message
}
func (target *Client) NumericReply(code NumericCode,

View File

@ -77,9 +77,14 @@ func (socket *Socket) WriteLine(line string) (err error) {
return
}
if _, err = socket.writer.WriteString(CRLF); socket.isError(err, W) {
return
}
if err = socket.writer.Flush(); socket.isError(err, W) {
return
}
if DEBUG_NET {
log.Printf("%s ← %s", socket, line)
}