mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Force single thread if small file Fixes #5
This commit is contained in:
parent
5a3e3ab782
commit
fd71dc2b78
1 changed files with 16 additions and 1 deletions
17
connect.go
17
connect.go
|
@ -65,6 +65,18 @@ func NewConnection(flags *Flags) *Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Connection) Run() {
|
func (c *Connection) Run() {
|
||||||
|
forceSingleThreaded := false
|
||||||
|
if c.IsSender {
|
||||||
|
fdata, err := ioutil.ReadFile(c.File.Name)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(fdata) < MAX_NUMBER_THREADS*BUFFERSIZE {
|
||||||
|
forceSingleThreaded = true
|
||||||
|
log.Debug("forcing single thread")
|
||||||
|
}
|
||||||
|
}
|
||||||
log.Debug("checking code validity")
|
log.Debug("checking code validity")
|
||||||
for {
|
for {
|
||||||
// check code
|
// check code
|
||||||
|
@ -73,7 +85,7 @@ func (c *Connection) Run() {
|
||||||
numThreads, errParse := strconv.Atoi(m[0])
|
numThreads, errParse := strconv.Atoi(m[0])
|
||||||
if len(m) < 2 {
|
if len(m) < 2 {
|
||||||
goodCode = false
|
goodCode = false
|
||||||
} else if numThreads > MAX_NUMBER_THREADS || numThreads < 1 {
|
} else if numThreads > MAX_NUMBER_THREADS || numThreads < 1 || (forceSingleThreaded && numThreads != 1) {
|
||||||
c.NumberOfConnections = MAX_NUMBER_THREADS
|
c.NumberOfConnections = MAX_NUMBER_THREADS
|
||||||
goodCode = false
|
goodCode = false
|
||||||
} else if errParse != nil {
|
} else if errParse != nil {
|
||||||
|
@ -82,6 +94,9 @@ func (c *Connection) Run() {
|
||||||
log.Debug(m)
|
log.Debug(m)
|
||||||
if !goodCode {
|
if !goodCode {
|
||||||
if c.IsSender {
|
if c.IsSender {
|
||||||
|
if forceSingleThreaded {
|
||||||
|
c.NumberOfConnections = 1
|
||||||
|
}
|
||||||
c.Code = strconv.Itoa(c.NumberOfConnections) + "-" + GetRandomName()
|
c.Code = strconv.Itoa(c.NumberOfConnections) + "-" + GetRandomName()
|
||||||
} else {
|
} else {
|
||||||
if len(c.Code) != 0 {
|
if len(c.Code) != 0 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue