mirror of https://github.com/fluffle/goirc
gofix weekly fixes for client.
This commit is contained in:
parent
81eb9ee3df
commit
9d5159a220
|
@ -3,12 +3,13 @@ package client
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"github.com/fluffle/goirc/event"
|
"github.com/fluffle/goirc/event"
|
||||||
"github.com/fluffle/goirc/logging"
|
"github.com/fluffle/goirc/logging"
|
||||||
"github.com/fluffle/goirc/state"
|
"github.com/fluffle/goirc/state"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -87,20 +88,20 @@ func Client(nick, ident, name string,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
conn := &Conn{
|
conn := &Conn{
|
||||||
ER: r,
|
ER: r,
|
||||||
ED: r,
|
ED: r,
|
||||||
l: l,
|
l: l,
|
||||||
st: false,
|
st: false,
|
||||||
in: make(chan *Line, 32),
|
in: make(chan *Line, 32),
|
||||||
out: make(chan string, 32),
|
out: make(chan string, 32),
|
||||||
cSend: make(chan bool),
|
cSend: make(chan bool),
|
||||||
cLoop: make(chan bool),
|
cLoop: make(chan bool),
|
||||||
SSL: false,
|
SSL: false,
|
||||||
SSLConfig: nil,
|
SSLConfig: nil,
|
||||||
Timeout: 300,
|
Timeout: 300,
|
||||||
Flood: false,
|
Flood: false,
|
||||||
badness: 0,
|
badness: 0,
|
||||||
lastsent: 0,
|
lastsent: 0,
|
||||||
}
|
}
|
||||||
conn.addIntHandlers()
|
conn.addIntHandlers()
|
||||||
conn.Me = state.NewNick(nick, l)
|
conn.Me = state.NewNick(nick, l)
|
||||||
|
@ -146,9 +147,9 @@ func (conn *Conn) initialise() {
|
||||||
// on the connection to the IRC server, set Conn.SSL to true before calling
|
// on the connection to the IRC server, set Conn.SSL to true before calling
|
||||||
// Connect(). The port will default to 6697 if ssl is enabled, and 6667
|
// Connect(). The port will default to 6697 if ssl is enabled, and 6667
|
||||||
// otherwise. You can also provide an optional connect password.
|
// otherwise. You can also provide an optional connect password.
|
||||||
func (conn *Conn) Connect(host string, pass ...string) os.Error {
|
func (conn *Conn) Connect(host string, pass ...string) error {
|
||||||
if conn.Connected {
|
if conn.Connected {
|
||||||
return os.NewError(fmt.Sprintf(
|
return errors.New(fmt.Sprintf(
|
||||||
"irc.Connect(): already connected to %s, cannot connect to %s",
|
"irc.Connect(): already connected to %s, cannot connect to %s",
|
||||||
conn.Host, host))
|
conn.Host, host))
|
||||||
}
|
}
|
||||||
|
@ -220,7 +221,7 @@ func (conn *Conn) recv() {
|
||||||
for {
|
for {
|
||||||
s, err := conn.io.ReadString('\n')
|
s, err := conn.io.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.l.Error("irc.recv(): %s", err.String())
|
conn.l.Error("irc.recv(): %s", err.Error())
|
||||||
conn.shutdown()
|
conn.shutdown()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -262,12 +263,12 @@ func (conn *Conn) write(line string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := conn.io.WriteString(line + "\r\n"); err != nil {
|
if _, err := conn.io.WriteString(line + "\r\n"); err != nil {
|
||||||
conn.l.Error("irc.send(): %s", err.String())
|
conn.l.Error("irc.send(): %s", err.Error())
|
||||||
conn.shutdown()
|
conn.shutdown()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := conn.io.Flush(); err != nil {
|
if err := conn.io.Flush(); err != nil {
|
||||||
conn.l.Error("irc.send(): %s", err.String())
|
conn.l.Error("irc.send(): %s", err.Error())
|
||||||
conn.shutdown()
|
conn.shutdown()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -96,7 +97,7 @@ func (m *mockNetConn) ExpectNothing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement net.Conn interface
|
// Implement net.Conn interface
|
||||||
func (m *mockNetConn) Read(b []byte) (int, os.Error) {
|
func (m *mockNetConn) Read(b []byte) (int, error) {
|
||||||
if m.closed {
|
if m.closed {
|
||||||
return 0, os.EINVAL
|
return 0, os.EINVAL
|
||||||
}
|
}
|
||||||
|
@ -106,12 +107,12 @@ func (m *mockNetConn) Read(b []byte) (int, os.Error) {
|
||||||
l = len(s)
|
l = len(s)
|
||||||
copy(b, s)
|
copy(b, s)
|
||||||
case <-m.closers[mockReadCloser]:
|
case <-m.closers[mockReadCloser]:
|
||||||
return 0, os.EOF
|
return 0, io.EOF
|
||||||
}
|
}
|
||||||
return l, nil
|
return l, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockNetConn) Write(s []byte) (int, os.Error) {
|
func (m *mockNetConn) Write(s []byte) (int, error) {
|
||||||
if m.closed {
|
if m.closed {
|
||||||
return 0, os.EINVAL
|
return 0, os.EINVAL
|
||||||
}
|
}
|
||||||
|
@ -121,7 +122,7 @@ func (m *mockNetConn) Write(s []byte) (int, os.Error) {
|
||||||
return len(s), nil
|
return len(s), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockNetConn) Close() os.Error {
|
func (m *mockNetConn) Close() error {
|
||||||
if m.closed {
|
if m.closed {
|
||||||
return os.EINVAL
|
return os.EINVAL
|
||||||
}
|
}
|
||||||
|
@ -142,18 +143,18 @@ func (m *mockNetConn) RemoteAddr() net.Addr {
|
||||||
return &net.IPAddr{net.IPv4(127, 0, 0, 1)}
|
return &net.IPAddr{net.IPv4(127, 0, 0, 1)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockNetConn) SetTimeout(ns int64) os.Error {
|
func (m *mockNetConn) SetTimeout(ns int64) error {
|
||||||
m.rt = ns
|
m.rt = ns
|
||||||
m.wt = ns
|
m.wt = ns
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockNetConn) SetReadTimeout(ns int64) os.Error {
|
func (m *mockNetConn) SetReadTimeout(ns int64) error {
|
||||||
m.rt = ns
|
m.rt = ns
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockNetConn) SetWriteTimeout(ns int64) os.Error {
|
func (m *mockNetConn) SetWriteTimeout(ns int64) error {
|
||||||
m.wt = ns
|
m.wt = ns
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue