3
0
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:
Jeremy Latt 2014-02-23 18:05:06 -08:00
parent 0856a9fa81
commit 41e6baf9d4
3 changed files with 6 additions and 18 deletions

View File

@ -286,7 +286,7 @@ func (channel *Channel) applyModeMember(client *Client, mode ChannelMode,
return false
}
func (channel *Channel) applyMode(client *Client, change ChannelModeChange) bool {
func (channel *Channel) applyMode(client *Client, change *ChannelModeChange) bool {
switch change.mode {
case BanMask, ExceptMask, InviteMask:
// TODO add/remove

View File

@ -438,7 +438,7 @@ func (change *ModeChange) String() string {
return fmt.Sprintf("%s%s", change.op, change.mode)
}
type ModeChanges []ModeChange
type ModeChanges []*ModeChange
func (changes ModeChanges) String() string {
if len(changes) == 0 {
@ -478,7 +478,7 @@ func NewUserModeCommand(args []string) (editableCommand, error) {
}
for _, mode := range modeChange[1:] {
cmd.changes = append(cmd.changes, ModeChange{
cmd.changes = append(cmd.changes, &ModeChange{
mode: UserMode(mode),
op: op,
})
@ -509,7 +509,7 @@ func (change *ChannelModeChange) String() (str string) {
return
}
type ChannelModeChanges []ChannelModeChange
type ChannelModeChanges []*ChannelModeChange
func (changes ChannelModeChanges) String() (str string) {
if len(changes) == 0 {
@ -558,7 +558,7 @@ func NewChannelModeCommand(args []string) (editableCommand, error) {
skipArgs := 1
for _, mode := range modeArg {
change := ChannelModeChange{
change := &ChannelModeChange{
mode: ChannelMode(mode),
op: op,
}

View File

@ -15,10 +15,9 @@ const (
)
type Socket struct {
closed bool
client *Client
conn net.Conn
reader *bufio.Reader
client *Client
writer *bufio.Writer
}
@ -40,10 +39,6 @@ func (socket *Socket) String() string {
}
func (socket *Socket) Close() {
if socket.closed {
return
}
socket.closed = true
socket.conn.Close()
if DEBUG_NET {
log.Printf("%s closed", socket)
@ -60,7 +55,6 @@ func (socket *Socket) readLines(commands chan<- Command) {
for {
line, err := socket.reader.ReadString('\n')
if socket.isError(err, R) {
socket.closed = true
break
}
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) {
if socket.closed {
return io.EOF
}
if _, err = socket.writer.WriteString(line); socket.isError(err, W) {
socket.closed = true
return
}
if _, err = socket.writer.WriteString(CRLF); socket.isError(err, W) {
socket.closed = true
return
}
if err = socket.writer.Flush(); socket.isError(err, W) {
socket.closed = true
return
}