Re: Dedicated Server API Client Communication
Posted: 04 May 2014, 00:06
SO many thanks









Hey, I saw that you replaced the \Maniaplanet\DedicatedServer\Structures\Player classes by \ManiaLive\Data\Player classThe_Big_Boo wrote:I had to do it for testing so why should you do the same job again?And as I know the changes I made, it's easier for me to find possible issues. ^^
Code: Select all
$data = '';
while(strlen($data) < $size)
{
$buf = fread($this->socket, $size - strlen($data));
if($buf === '' || $buf === false)
return false;
$data .= $buf;
}
It's actually a blocking fread: it returns false when it times out, which is after 5s by default but can be configured. I don't think a server controller can afford waiting minutes... 5s without a single byte when you're waiting for an immediate answer is not that short.Jojo_44 wrote:Since you have a non-blocking fread it can happen that it trys to read something from the stream when no bytes are available. But you return false in that case(line 264 first if case). I don´t know why you have a if there anyway but I think you should remove the if(line 264/265).
The goal is still to merge my fork back in the original.Jojo_44 wrote:Btw it would be nice if you can update the composer json because the current one is pointing to the original dedicated library because of the fork you did I guess.
Are you sure ? What´s the reason behind this comparison in the if statement ?The_Big_Boo wrote:It's actually a blocking fread: it returns false when it times out, which is after 5s by default but can be configured. I don't think a server controller can afford waiting minutes... 5s without a single byte when you're waiting for an immediate answer is not that short.Jojo_44 wrote:Since you have a non-blocking fread it can happen that it trys to read something from the stream when no bytes are available. But you return false in that case(line 264 first if case). I don´t know why you have a if there anyway but I think you should remove the if(line 264/265).
Code: Select all
$buf === ''
Though fread should return false when reaching eof in our case, better safe than sorry.The streams listed in the read array will be watched to see if characters become available for reading (more precisely, to see if a read will not block - in particular, a stream resource is also ready on end-of-file, in which case an fread() will return a zero length string).
For a stream, eof means the connection was closed. As long as the connection is alive, eof isn't supposed to be reached even if there are no data available. Moreover, the exception was thrown while trying to read the header, thus the 8 first bytes of answer, and it seems it's the most common case (maybe even the only case) of "random" interrupt exception.Jojo_44 wrote:After that fread gets called instantly but since GetMapList() can take 2sec to transmit all data to the client there´s a point where maybe half of the data was read but furthermore no data available(End of file). End of file means fread returns empty string and empty string means you return false what also means you throw an Exception.