mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-13 07:29:30 +01:00
don't wait for writing to complete
This commit is contained in:
parent
9960089226
commit
c0dc733351
@ -17,7 +17,6 @@ type Client struct {
|
|||||||
awayMessage string
|
awayMessage string
|
||||||
channels ChannelSet
|
channels ChannelSet
|
||||||
ctime time.Time
|
ctime time.Time
|
||||||
doneWriting chan bool
|
|
||||||
flags map[UserMode]bool
|
flags map[UserMode]bool
|
||||||
hasQuit bool
|
hasQuit bool
|
||||||
hops uint
|
hops uint
|
||||||
@ -37,16 +36,15 @@ type Client struct {
|
|||||||
func NewClient(server *Server, conn net.Conn) *Client {
|
func NewClient(server *Server, conn net.Conn) *Client {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
client := &Client{
|
client := &Client{
|
||||||
atime: now,
|
atime: now,
|
||||||
channels: make(ChannelSet),
|
channels: make(ChannelSet),
|
||||||
ctime: now,
|
ctime: now,
|
||||||
doneWriting: make(chan bool),
|
flags: make(map[UserMode]bool),
|
||||||
flags: make(map[UserMode]bool),
|
hostname: AddrLookupHostname(conn.RemoteAddr()),
|
||||||
hostname: AddrLookupHostname(conn.RemoteAddr()),
|
phase: server.InitPhase(),
|
||||||
phase: server.InitPhase(),
|
server: server,
|
||||||
server: server,
|
socket: NewSocket(conn),
|
||||||
socket: NewSocket(conn),
|
replies: make(chan string, 16),
|
||||||
replies: make(chan string),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client.loginTimer = time.AfterFunc(LOGIN_TIMEOUT, client.connectionTimeout)
|
client.loginTimer = time.AfterFunc(LOGIN_TIMEOUT, client.connectionTimeout)
|
||||||
@ -97,10 +95,11 @@ func (client *Client) connectionClosed() {
|
|||||||
|
|
||||||
func (client *Client) writeReplies() {
|
func (client *Client) writeReplies() {
|
||||||
for reply := range client.replies {
|
for reply := range client.replies {
|
||||||
client.socket.Write(reply)
|
if client.socket.Write(reply) != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.socket.Close()
|
client.socket.Close()
|
||||||
client.doneWriting <- true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -163,7 +162,7 @@ func (client *Client) destroy() {
|
|||||||
// clean up self
|
// clean up self
|
||||||
|
|
||||||
close(client.replies)
|
close(client.replies)
|
||||||
<-client.doneWriting
|
|
||||||
client.loginTimer.Stop()
|
client.loginTimer.Stop()
|
||||||
|
|
||||||
if client.idleTimer != nil {
|
if client.idleTimer != nil {
|
||||||
|
@ -10,14 +10,14 @@ func NewStringReply(source Identifier, code StringCode,
|
|||||||
format string, args ...interface{}) string {
|
format string, args ...interface{}) string {
|
||||||
header := fmt.Sprintf(":%s %s ", source, code)
|
header := fmt.Sprintf(":%s %s ", source, code)
|
||||||
message := fmt.Sprintf(format, args...)
|
message := fmt.Sprintf(format, args...)
|
||||||
return header + message + CRLF
|
return header + message
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNumericReply(target *Client, code NumericCode,
|
func NewNumericReply(target *Client, code NumericCode,
|
||||||
format string, args ...interface{}) string {
|
format string, args ...interface{}) string {
|
||||||
header := fmt.Sprintf(":%s %s %s ", target.server.Id(), code, target.Nick())
|
header := fmt.Sprintf(":%s %s %s ", target.server.Id(), code, target.Nick())
|
||||||
message := fmt.Sprintf(format, args...)
|
message := fmt.Sprintf(format, args...)
|
||||||
return header + message + CRLF
|
return header + message
|
||||||
}
|
}
|
||||||
|
|
||||||
func (target *Client) NumericReply(code NumericCode,
|
func (target *Client) NumericReply(code NumericCode,
|
||||||
|
@ -77,9 +77,14 @@ func (socket *Socket) WriteLine(line string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err = socket.writer.WriteString(CRLF); socket.isError(err, W) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err = socket.writer.Flush(); socket.isError(err, W) {
|
if err = socket.writer.Flush(); socket.isError(err, W) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if DEBUG_NET {
|
if DEBUG_NET {
|
||||||
log.Printf("%s ← %s", socket, line)
|
log.Printf("%s ← %s", socket, line)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user