mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
get rid of a race; use pointers where possible
This commit is contained in:
parent
0856a9fa81
commit
41e6baf9d4
@ -286,7 +286,7 @@ func (channel *Channel) applyModeMember(client *Client, mode ChannelMode,
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (channel *Channel) applyMode(client *Client, change ChannelModeChange) bool {
|
func (channel *Channel) applyMode(client *Client, change *ChannelModeChange) bool {
|
||||||
switch change.mode {
|
switch change.mode {
|
||||||
case BanMask, ExceptMask, InviteMask:
|
case BanMask, ExceptMask, InviteMask:
|
||||||
// TODO add/remove
|
// TODO add/remove
|
||||||
|
@ -438,7 +438,7 @@ func (change *ModeChange) String() string {
|
|||||||
return fmt.Sprintf("%s%s", change.op, change.mode)
|
return fmt.Sprintf("%s%s", change.op, change.mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ModeChanges []ModeChange
|
type ModeChanges []*ModeChange
|
||||||
|
|
||||||
func (changes ModeChanges) String() string {
|
func (changes ModeChanges) String() string {
|
||||||
if len(changes) == 0 {
|
if len(changes) == 0 {
|
||||||
@ -478,7 +478,7 @@ func NewUserModeCommand(args []string) (editableCommand, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, mode := range modeChange[1:] {
|
for _, mode := range modeChange[1:] {
|
||||||
cmd.changes = append(cmd.changes, ModeChange{
|
cmd.changes = append(cmd.changes, &ModeChange{
|
||||||
mode: UserMode(mode),
|
mode: UserMode(mode),
|
||||||
op: op,
|
op: op,
|
||||||
})
|
})
|
||||||
@ -509,7 +509,7 @@ func (change *ChannelModeChange) String() (str string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChannelModeChanges []ChannelModeChange
|
type ChannelModeChanges []*ChannelModeChange
|
||||||
|
|
||||||
func (changes ChannelModeChanges) String() (str string) {
|
func (changes ChannelModeChanges) String() (str string) {
|
||||||
if len(changes) == 0 {
|
if len(changes) == 0 {
|
||||||
@ -558,7 +558,7 @@ func NewChannelModeCommand(args []string) (editableCommand, error) {
|
|||||||
|
|
||||||
skipArgs := 1
|
skipArgs := 1
|
||||||
for _, mode := range modeArg {
|
for _, mode := range modeArg {
|
||||||
change := ChannelModeChange{
|
change := &ChannelModeChange{
|
||||||
mode: ChannelMode(mode),
|
mode: ChannelMode(mode),
|
||||||
op: op,
|
op: op,
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Socket struct {
|
type Socket struct {
|
||||||
closed bool
|
client *Client
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
reader *bufio.Reader
|
reader *bufio.Reader
|
||||||
client *Client
|
|
||||||
writer *bufio.Writer
|
writer *bufio.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,10 +39,6 @@ func (socket *Socket) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (socket *Socket) Close() {
|
func (socket *Socket) Close() {
|
||||||
if socket.closed {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
socket.closed = true
|
|
||||||
socket.conn.Close()
|
socket.conn.Close()
|
||||||
if DEBUG_NET {
|
if DEBUG_NET {
|
||||||
log.Printf("%s closed", socket)
|
log.Printf("%s closed", socket)
|
||||||
@ -60,7 +55,6 @@ func (socket *Socket) readLines(commands chan<- Command) {
|
|||||||
for {
|
for {
|
||||||
line, err := socket.reader.ReadString('\n')
|
line, err := socket.reader.ReadString('\n')
|
||||||
if socket.isError(err, R) {
|
if socket.isError(err, R) {
|
||||||
socket.closed = true
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
line = strings.TrimRight(line, "\r\n")
|
line = strings.TrimRight(line, "\r\n")
|
||||||
@ -88,21 +82,15 @@ func (socket *Socket) readLines(commands chan<- Command) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (socket *Socket) Write(line string) (err error) {
|
func (socket *Socket) Write(line string) (err error) {
|
||||||
if socket.closed {
|
|
||||||
return io.EOF
|
|
||||||
}
|
|
||||||
if _, err = socket.writer.WriteString(line); socket.isError(err, W) {
|
if _, err = socket.writer.WriteString(line); socket.isError(err, W) {
|
||||||
socket.closed = true
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = socket.writer.WriteString(CRLF); socket.isError(err, W) {
|
if _, err = socket.writer.WriteString(CRLF); socket.isError(err, W) {
|
||||||
socket.closed = true
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = socket.writer.Flush(); socket.isError(err, W) {
|
if err = socket.writer.Flush(); socket.isError(err, W) {
|
||||||
socket.closed = true
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user