Skip to content

Commit

Permalink
Don't use atomic insn�. to count concurrent client connections.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Feb 28, 2013
1 parent 8f94dcf commit 441beeb
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cmd/shadowsocks-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"runtime"
"strconv"
"sync"
"sync/atomic"
"syscall"
)

Expand Down Expand Up @@ -83,13 +82,13 @@ func getRequest(conn *ss.Conn) (host string, extra []byte, err error) {

const logCntDelta = 100

var connCnt int32
var nextLogConnCnt int32 = logCntDelta
var connCnt int
var nextLogConnCnt int = logCntDelta

func handleConnection(conn *ss.Conn) {
var host string

atomic.AddInt32(&connCnt, 1)
connCnt++ // this maybe not accurate, but should be enough
if connCnt-nextLogConnCnt >= 0 {
// XXX There's no xadd in the atomic package, so it's difficult to log
// the message only once with low cost. Also note nextLogConnCnt maybe
Expand All @@ -108,7 +107,7 @@ func handleConnection(conn *ss.Conn) {
if debug {
debug.Printf("closed pipe %s<->%s\n", conn.RemoteAddr(), host)
}
atomic.AddInt32(&connCnt, -1)
connCnt--
if !closed {
conn.Close()
}
Expand Down

0 comments on commit 441beeb

Please sign in to comment.