Merge pull request #128 from akihiro/master
Add non UTF-8 encoding support
This commit is contained in:
commit
8e7ce4b5a1
2
go.mod
2
go.mod
@ -1,3 +1,5 @@
|
||||
module github.com/thoj/go-ircevent
|
||||
|
||||
go 1.12
|
||||
|
||||
require golang.org/x/text v0.3.2
|
||||
|
3
go.sum
Normal file
3
go.sum
Normal file
@ -0,0 +1,3 @@
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
12
irc.go
12
irc.go
@ -30,6 +30,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/encoding"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -43,7 +45,8 @@ var ErrDisconnected = errors.New("Disconnect Called")
|
||||
// Read data from a connection. To be used as a goroutine.
|
||||
func (irc *Connection) readLoop() {
|
||||
defer irc.Done()
|
||||
br := bufio.NewReaderSize(irc.socket, 512)
|
||||
r := irc.Encoding.NewDecoder().Reader(irc.socket)
|
||||
br := bufio.NewReaderSize(r, 512)
|
||||
|
||||
errChan := irc.ErrorChan()
|
||||
|
||||
@ -157,6 +160,7 @@ func parseToEvent(msg string) (*Event, error) {
|
||||
// Loop to write to a connection. To be used as a goroutine.
|
||||
func (irc *Connection) writeLoop() {
|
||||
defer irc.Done()
|
||||
w := irc.Encoding.NewEncoder().Writer(irc.socket)
|
||||
errChan := irc.ErrorChan()
|
||||
for {
|
||||
select {
|
||||
@ -174,7 +178,7 @@ func (irc *Connection) writeLoop() {
|
||||
// Set a write deadline based on the time out
|
||||
irc.socket.SetWriteDeadline(time.Now().Add(irc.Timeout))
|
||||
|
||||
_, err := irc.socket.Write([]byte(b))
|
||||
_, err := w.Write([]byte(b))
|
||||
|
||||
// Past blocking write, bin timeout
|
||||
var zero time.Time
|
||||
@ -467,6 +471,10 @@ func (irc *Connection) Connect(server string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if irc.Encoding == nil {
|
||||
irc.Encoding = encoding.Nop
|
||||
}
|
||||
|
||||
irc.stopped = false
|
||||
irc.Log.Printf("Connected to %s (%s)\n", irc.Server, irc.socket.RemoteAddr())
|
||||
|
||||
|
@ -12,6 +12,8 @@ import (
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/encoding"
|
||||
)
|
||||
|
||||
type Connection struct {
|
||||
@ -35,6 +37,7 @@ type Connection struct {
|
||||
PingFreq time.Duration
|
||||
KeepAlive time.Duration
|
||||
Server string
|
||||
Encoding encoding.Encoding
|
||||
|
||||
RealName string // The real name we want to display.
|
||||
// If zero-value defaults to the user.
|
||||
|
Loading…
Reference in New Issue
Block a user