-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skip not complete HTTP messages #953
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,23 +184,27 @@ type MessageParser struct { | |
maxSize size.Size // maximum message size, default 5mb | ||
m map[uint64]*Message | ||
|
||
messageExpire time.Duration // the maximum time to wait for the final packet, minimum is 100ms | ||
End HintEnd | ||
Start HintStart | ||
ticker *time.Ticker | ||
messages chan *Message | ||
packets chan *Packet | ||
close chan struct{} // to signal that we are able to close | ||
messageExpire time.Duration // the maximum time to wait for the final packet, minimum is 100ms | ||
allowIncompete bool | ||
End HintEnd | ||
Start HintStart | ||
ticker *time.Ticker | ||
messages chan *Message | ||
packets chan *Packet | ||
close chan struct{} // to signal that we are able to close | ||
} | ||
|
||
// NewMessageParser returns a new instance of message parser | ||
func NewMessageParser(maxSize size.Size, messageExpire time.Duration, debugger Debugger) (parser *MessageParser) { | ||
func NewMessageParser(maxSize size.Size, messageExpire time.Duration, allowIncompete bool, debugger Debugger) (parser *MessageParser) { | ||
parser = new(MessageParser) | ||
parser.debug = debugger | ||
parser.messageExpire = time.Millisecond * 100 | ||
if parser.messageExpire < messageExpire { | ||
parser.messageExpire = messageExpire | ||
|
||
parser.messageExpire = messageExpire | ||
if parser.messageExpire == 0 { | ||
parser.messageExpire = time.Millisecond * 500 | ||
} | ||
|
||
parser.allowIncompete = allowIncompete | ||
parser.maxSize = maxSize | ||
if parser.maxSize < 1 { | ||
parser.maxSize = 5 << 20 | ||
|
@@ -224,8 +228,6 @@ func (parser *MessageParser) PacketHandler(packet *Packet) { | |
parser.packets <- packet | ||
} | ||
|
||
var processedPackets int | ||
|
||
func (parser *MessageParser) wait() { | ||
var ( | ||
now time.Time | ||
|
@@ -271,6 +273,8 @@ func (parser *MessageParser) processPacket(pckt *Packet) { | |
} | ||
return | ||
} | ||
default: | ||
in = pckt.Incoming | ||
} | ||
|
||
m = new(Message) | ||
|
@@ -288,23 +292,29 @@ func (parser *MessageParser) addPacket(m *Message, pckt *Packet) { | |
pckt.Payload = pckt.Payload[:int(parser.maxSize)-m.Length] | ||
} | ||
m.add(pckt) | ||
switch { | ||
// if one of this cases matches, we dispatch the message | ||
case trunc >= 0: | ||
case parser.End != nil && parser.End(m): | ||
default: | ||
// continue to receive packets | ||
|
||
if trunc > 0 { | ||
return | ||
} | ||
|
||
parser.Emit(m) | ||
// If we are using protocol parsing, like HTTP, depend on its parsing func. | ||
// For the binary procols wait for message to expire | ||
if parser.End != nil { | ||
if parser.End(m) { | ||
parser.Emit(m) | ||
} | ||
} | ||
} | ||
|
||
func (parser *MessageParser) Read() *Message { | ||
m := <-parser.messages | ||
return m | ||
} | ||
|
||
func (parser *MessageParser) Messages() chan *Message { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported method MessageParser.Messages should have comment or be unexported |
||
return parser.messages | ||
} | ||
|
||
func (parser *MessageParser) Emit(m *Message) { | ||
delete(parser.m, m.packets[0].MessageID()) | ||
|
||
|
@@ -321,7 +331,13 @@ func (parser *MessageParser) timer(now time.Time) { | |
for _, m := range parser.m { | ||
if now.Sub(m.End) > parser.messageExpire { | ||
m.TimedOut = true | ||
parser.Emit(m) | ||
if parser.End == nil || parser.allowIncompete { | ||
parser.Emit(m) | ||
} else { | ||
// Just remove | ||
delete(parser.m, m.packets[0].MessageID()) | ||
m.Finalize() | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method MessageParser.Messages should have comment or be unexported