|
@@ -246,7 +246,14 @@ class TcpConnection extends ConnectionInterface
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if ($this->_status === self::STATUS_INITIAL || $this->_status === self::STATUS_CONNECTING) {
|
|
if ($this->_status === self::STATUS_INITIAL || $this->_status === self::STATUS_CONNECTING) {
|
|
|
|
|
+ if ($this->_sendBuffer) {
|
|
|
|
|
+ if ($this->bufferIsFull()) {
|
|
|
|
|
+ self::$statistics['send_fail']++;
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
$this->_sendBuffer .= $send_buffer;
|
|
$this->_sendBuffer .= $send_buffer;
|
|
|
|
|
+ $this->checkBufferWillFull();
|
|
|
return null;
|
|
return null;
|
|
|
} elseif ($this->_status === self::STATUS_CLOSING || $this->_status === self::STATUS_CLOSED) {
|
|
} elseif ($this->_status === self::STATUS_CLOSING || $this->_status === self::STATUS_CLOSED) {
|
|
|
return false;
|
|
return false;
|
|
@@ -283,29 +290,18 @@ class TcpConnection extends ConnectionInterface
|
|
|
$this->_sendBuffer = $send_buffer;
|
|
$this->_sendBuffer = $send_buffer;
|
|
|
}
|
|
}
|
|
|
Worker::$globalEvent->add($this->_socket, EventInterface::EV_WRITE, array($this, 'baseWrite'));
|
|
Worker::$globalEvent->add($this->_socket, EventInterface::EV_WRITE, array($this, 'baseWrite'));
|
|
|
- // Check if the send buffer is full.
|
|
|
|
|
- $this->checkBufferIsFull();
|
|
|
|
|
|
|
+ // Check if the send buffer will be full.
|
|
|
|
|
+ $this->checkBufferWillFull();
|
|
|
return null;
|
|
return null;
|
|
|
} else {
|
|
} else {
|
|
|
- // Buffer has been marked as full but still has data to send the packet is discarded.
|
|
|
|
|
- if ($this->maxSendBufferSize <= strlen($this->_sendBuffer)) {
|
|
|
|
|
|
|
+ if ($this->bufferIsFull()) {
|
|
|
self::$statistics['send_fail']++;
|
|
self::$statistics['send_fail']++;
|
|
|
- if ($this->onError) {
|
|
|
|
|
- try {
|
|
|
|
|
- call_user_func($this->onError, $this, WORKERMAN_SEND_FAIL, 'send buffer full and drop package');
|
|
|
|
|
- } catch (\Exception $e) {
|
|
|
|
|
- Worker::log($e);
|
|
|
|
|
- exit(250);
|
|
|
|
|
- } catch (\Error $e) {
|
|
|
|
|
- Worker::log($e);
|
|
|
|
|
- exit(250);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
$this->_sendBuffer .= $send_buffer;
|
|
$this->_sendBuffer .= $send_buffer;
|
|
|
// Check if the send buffer is full.
|
|
// Check if the send buffer is full.
|
|
|
- $this->checkBufferIsFull();
|
|
|
|
|
|
|
+ $this->checkBufferWillFull();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -568,11 +564,11 @@ class TcpConnection extends ConnectionInterface
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Check whether the send buffer is full.
|
|
|
|
|
|
|
+ * Check whether the send buffer will be full.
|
|
|
*
|
|
*
|
|
|
* @return void
|
|
* @return void
|
|
|
*/
|
|
*/
|
|
|
- protected function checkBufferIsFull()
|
|
|
|
|
|
|
+ protected function checkBufferWillFull()
|
|
|
{
|
|
{
|
|
|
if ($this->maxSendBufferSize <= strlen($this->_sendBuffer)) {
|
|
if ($this->maxSendBufferSize <= strlen($this->_sendBuffer)) {
|
|
|
if ($this->onBufferFull) {
|
|
if ($this->onBufferFull) {
|
|
@@ -590,6 +586,31 @@ class TcpConnection extends ConnectionInterface
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * Whether send buffer is full.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return bool
|
|
|
|
|
+ */
|
|
|
|
|
+ protected function bufferIsFull()
|
|
|
|
|
+ {
|
|
|
|
|
+ // Buffer has been marked as full but still has data to send then the packet is discarded.
|
|
|
|
|
+ if ($this->maxSendBufferSize <= strlen($this->_sendBuffer)) {
|
|
|
|
|
+ if ($this->onError) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ call_user_func($this->onError, $this, WORKERMAN_SEND_FAIL, 'send buffer full and drop package');
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Worker::log($e);
|
|
|
|
|
+ exit(250);
|
|
|
|
|
+ } catch (\Error $e) {
|
|
|
|
|
+ Worker::log($e);
|
|
|
|
|
+ exit(250);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* Destroy connection.
|
|
* Destroy connection.
|
|
|
*
|
|
*
|
|
|
* @return void
|
|
* @return void
|