2015-10-11 08:12:55 +00:00
|
|
|
/*
|
|
|
|
goircd -- minimalistic simple Internet Relay Chat (IRC) server
|
2020-01-07 15:27:02 +00:00
|
|
|
Copyright (C) 2014-2020 Sergey Matveev <stargrave@stargrave.org>
|
2015-10-11 08:12:55 +00:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2019-09-27 08:32:53 +00:00
|
|
|
the Free Software Foundation, version 3 of the License.
|
2015-10-11 08:12:55 +00:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-11-06 17:10:06 +00:00
|
|
|
"io"
|
2015-10-11 08:12:55 +00:00
|
|
|
"net"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TestingConn struct {
|
|
|
|
inbound chan string
|
|
|
|
outbound chan string
|
2020-11-06 17:10:06 +00:00
|
|
|
closed chan struct{}
|
2015-10-11 08:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewTestingConn() *TestingConn {
|
2020-11-06 17:10:06 +00:00
|
|
|
return &TestingConn{
|
|
|
|
inbound: make(chan string, 8),
|
|
|
|
outbound: make(chan string, 8),
|
|
|
|
closed: make(chan struct{}),
|
|
|
|
}
|
2015-10-11 08:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (conn TestingConn) Error() string {
|
|
|
|
return "i am finished"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conn *TestingConn) Read(b []byte) (n int, err error) {
|
2020-11-06 17:10:06 +00:00
|
|
|
select {
|
|
|
|
case msg := <-conn.inbound:
|
|
|
|
if msg == "" {
|
|
|
|
return 0, conn
|
|
|
|
}
|
|
|
|
for n, bt := range append([]byte(msg), CRLF...) {
|
|
|
|
b[n] = bt
|
|
|
|
}
|
|
|
|
return len(msg) + 2, nil
|
|
|
|
case <-conn.closed:
|
|
|
|
return 0, io.EOF
|
2015-10-11 08:12:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type MyAddr struct{}
|
|
|
|
|
|
|
|
func (a MyAddr) String() string {
|
|
|
|
return "someclient"
|
|
|
|
}
|
|
|
|
func (a MyAddr) Network() string {
|
|
|
|
return "somenet"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conn *TestingConn) Write(b []byte) (n int, err error) {
|
|
|
|
conn.outbound <- string(b)
|
|
|
|
return len(b), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conn *TestingConn) Close() error {
|
2020-11-06 17:10:06 +00:00
|
|
|
close(conn.closed)
|
2015-10-11 08:12:55 +00:00
|
|
|
close(conn.outbound)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conn TestingConn) LocalAddr() net.Addr {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conn TestingConn) RemoteAddr() net.Addr {
|
|
|
|
return MyAddr{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conn TestingConn) SetDeadline(t time.Time) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conn TestingConn) SetReadDeadline(t time.Time) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conn TestingConn) SetWriteDeadline(t time.Time) error {
|
|
|
|
return nil
|
|
|
|
}
|