Skip to content

Commit

Permalink
fix: tcp package length type error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jul 18, 2019
1 parent 129f9ea commit e804f2c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/tcp-server/src/Swoole/ReceiveListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function onReceive(Server $server, int $fd, int $reactorId, string $data)
$response = Response::new($fd);
$request = Request::new($fd, $data, $reactorId);

server()->log("Receive: conn#{$fd} begin init context, received data: {$data}", [], 'debug');
server()->log("Receive: conn#{$fd} received client request, begin init context", [], 'debug');

$sid = (string)$fd;
$ctx = TcpReceiveContext::new($fd, $request, $response);
Expand Down
8 changes: 5 additions & 3 deletions src/tcp/src/Protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function unpack(string $data): Package
{
[$head, $body] = $this->unpackData($data);

return $this->getPacker($head['type'])->decode($body);
return $this->getPacker((string)$head['type'])->decode($body);
}

/**
Expand Down Expand Up @@ -199,7 +199,7 @@ public function unpackResponse(string $data): Response
{
[$head, $body] = $this->unpackData($data);

return $this->getPacker($head['type'])->decodeResponse($body);
return $this->getPacker((string)$head['type'])->decodeResponse($body);
}

/**
Expand Down Expand Up @@ -236,8 +236,10 @@ public function packBody(string $body): string
// Use length check
$format = self::HEADER_PACK_FORMAT;

// TODO
// Args sort please see self::HEADER_UNPACK_FORMAT
return pack($format, 0, $this->type, strlen($body), 0) . $body;
// return pack($format, 0, $this->type, strlen($body), 0) . $body;
return pack($format, 0, 0, strlen($body), 0) . $body;
}

/**
Expand Down

0 comments on commit e804f2c

Please sign in to comment.