我在PHP中有以下代码,我正在从c ++代码转换此代码。
这是C ++代码,如果你想分析那么。
这是PHP代码。
// just read the size to avoid reading 2 messages at once
$this->m_MsgSize = socket_recv($Socket, $this->m_MsgBuf, 2, 0);
// for now we expect 2 bytes at once, it should not be splitted
$DataSize = (int) (ord($this->m_MsgBuf[0]) | ord($this->m_MsgBuf[1]) >> 8);
if(($this->m_MsgSize != 2) || ($DataSize > ($this->NetworkMaxSize - 2)))
{
$this->ResetBuffer();
return false;
}
// read the real data
$this->m_MsgSize += socket_recv($Socket, $this->m_MsgBuf + 2, $DataSize, 0);
$NewDataSize = (int) (ord($this->m_MsgBuf[0]) | ord($this->m_MsgBuf[1]) >> 8);
echo $NewDataSize."\n";
// we got something unexpected/incomplete
if(($this->m_MsgSize <= 2) || ($NewDataSize != ($this->m_MsgSize - 2)))
{
$this->ResetBuffer();
return false;
}
// ok, ...reading starts after the size
$this->m_ReadPos = 2;
问题出在这一行
$this->m_MsgSize += socket_recv($Socket, $this->m_MsgBuf + 2, $DataSize, 0);
从c ++代码转换为此行,链接位于此问题的顶部。
m_MsgSize += recv(socket, (char*)m_MsgBuf+2, datasize, 0);
当我写($m_MsgBuf + 2)
时,php返回php only variables should be passed by reference
,当我在$m_MsgBuf += 2;
之前或之后写$m_MsgBuf = $m_MsgBuf + 2;
或socket_recv
时..下一个变量名为{ {1}}不会返回任何值。
问题是..如何在PHP中向缓冲区变量添加+ 2缓冲区?