Skip to content

Commit adef40d

Browse files
authored
Merge pull request #69 from WarriorXK/hotfix/3.1.1
[WIP] Hotfix/3.1.1
2 parents 3bb00d5 + 4469bb6 commit adef40d

21 files changed

+92
-33
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.0
1+
3.1.1

src/PHPWebSockets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* - - - - - - - - - - - - - BEGIN LICENSE BLOCK - - - - - - - - - - - - -
77
* The MIT License (MIT)
88
*
9-
* Copyright (c) 2020 Kevin Meijer
9+
* Copyright (c) 2021 Kevin Meijer
1010
*
1111
* Permission is hereby granted, free of charge, to any person obtaining a copy
1212
* of this software and associated documentation files (the "Software"), to deal

src/PHPWebSockets/AConnection.php

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* - - - - - - - - - - - - - BEGIN LICENSE BLOCK - - - - - - - - - - - - -
77
* The MIT License (MIT)
88
*
9-
* Copyright (c) 2020 Kevin Meijer
9+
* Copyright (c) 2021 Kevin Meijer
1010
*
1111
* Permission is hereby granted, free of charge, to any person obtaining a copy
1212
* of this software and associated documentation files (the "Software"), to deal
@@ -131,7 +131,7 @@ abstract class AConnection implements IStreamContainer, LoggerAwareInterface, IT
131131
/**
132132
* The timestamp since when this connection has been opened
133133
*
134-
* @var int
134+
* @var float|null
135135
*/
136136
protected $_openedTimestamp = NULL;
137137

@@ -215,7 +215,7 @@ abstract class AConnection implements IStreamContainer, LoggerAwareInterface, IT
215215
/**
216216
* The resource stream
217217
*
218-
* @var resource
218+
* @var resource|null
219219
*/
220220
protected $_stream = NULL;
221221

@@ -478,9 +478,10 @@ protected function _handlePacket(string $newData) : \Generator {
478478

479479
if ($res === FALSE) {
480480

481-
$this->close();
482481
yield new Update\Error(Update\Error::C_WRITE_INVALID_TARGET_STREAM, $this);
483482

483+
$this->close();
484+
484485
}
485486

486487
} else {
@@ -540,10 +541,10 @@ protected function _handlePacket(string $newData) : \Generator {
540541

541542
$this->_isClosed = TRUE;
542543

543-
$this->close();
544-
545544
yield new Update\Read(Update\Read::C_SOCK_DISCONNECT, $this);
546545

546+
$this->close();
547+
547548
} elseif (!$this->_weSentDisconnect) {
548549

549550
$this->_log(LogLevel::DEBUG, ' Remote initiated the disconnect, echo disconnect');
@@ -717,7 +718,18 @@ public function writeMultiFramed(string $data, int $opcode = \PHPWebSockets::OPC
717718
throw new \LogicException('FrameSize should be at least 1');
718719
}
719720

720-
$frames = str_split($data, $frameSize);
721+
$dataLen = strlen($data);
722+
if (strlen($data) > $frameSize) {
723+
724+
$frames = str_split($data, $frameSize);
725+
if ($frames === FALSE) {
726+
throw new \UnexpectedValueException('Unable to split ' . $dataLen . ' bytes into frames of ' . $frameSize . ' bytes');
727+
}
728+
729+
} else {
730+
$frames = [$data];
731+
}
732+
721733
end($frames);
722734
$lastKey = key($frames);
723735

@@ -757,6 +769,10 @@ protected function _getStreamForNewMessage(array $headers) {
757769
*/
758770
public function writeRaw(string $data, bool $priority) : void {
759771

772+
if (!$this->isOpen()) {
773+
throw new \LogicException('Unable to write: Connection is closed');
774+
}
775+
760776
if ($priority) {
761777
$this->_priorityFramesBuffer[] = $data;
762778
} else {
@@ -859,7 +875,7 @@ public function setNewMessageStreamCallback(callable $callable = NULL) : void {
859875
/**
860876
* Returns the stream object for this connection
861877
*
862-
* @return resource
878+
* @return resource|null
863879
*/
864880
public function getStream() {
865881
return $this->_stream;
@@ -960,10 +976,31 @@ public function close() : void {
960976
$this->_isClosed = TRUE;
961977

962978
if (is_resource($this->_stream)) {
963-
fclose($this->_stream);
979+
980+
$stream = $this->_stream;
964981
$this->_stream = NULL;
982+
983+
fclose($stream);
984+
965985
}
966986

987+
// To prevent the warning that there was still data to write
988+
$this->_clearBuffers();
989+
$this->_resetFrameData();
990+
991+
}
992+
993+
/**
994+
* Clears all buffers
995+
*/
996+
private function _clearBuffers() : void {
997+
998+
$this->_currentFrameRemainingBytes = 0;
999+
$this->_priorityFramesBuffer = [];
1000+
$this->_framesBuffer = [];
1001+
$this->_writeBuffer = NULL;
1002+
$this->_readBuffer = NULL;
1003+
9671004
}
9681005

9691006
/**

src/PHPWebSockets/AUpdate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* - - - - - - - - - - - - - BEGIN LICENSE BLOCK - - - - - - - - - - - - -
77
* The MIT License (MIT)
88
*
9-
* Copyright (c) 2020 Kevin Meijer
9+
* Copyright (c) 2021 Kevin Meijer
1010
*
1111
* Permission is hereby granted, free of charge, to any person obtaining a copy
1212
* of this software and associated documentation files (the "Software"), to deal

src/PHPWebSockets/BasicLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* - - - - - - - - - - - - - BEGIN LICENSE BLOCK - - - - - - - - - - - - -
77
* The MIT License (MIT)
88
*
9-
* Copyright (c) 2020 Kevin Meijer
9+
* Copyright (c) 2021 Kevin Meijer
1010
*
1111
* Permission is hereby granted, free of charge, to any person obtaining a copy
1212
* of this software and associated documentation files (the "Software"), to deal

src/PHPWebSockets/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* - - - - - - - - - - - - - BEGIN LICENSE BLOCK - - - - - - - - - - - - -
77
* The MIT License (MIT)
88
*
9-
* Copyright (c) 2020 Kevin Meijer
9+
* Copyright (c) 2021 Kevin Meijer
1010
*
1111
* Permission is hereby granted, free of charge, to any person obtaining a copy
1212
* of this software and associated documentation files (the "Software"), to deal

src/PHPWebSockets/Framer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* - - - - - - - - - - - - - BEGIN LICENSE BLOCK - - - - - - - - - - - - -
77
* The MIT License (MIT)
88
*
9-
* Copyright (c) 2020 Kevin Meijer
9+
* Copyright (c) 2021 Kevin Meijer
1010
*
1111
* Permission is hereby granted, free of charge, to any person obtaining a copy
1212
* of this software and associated documentation files (the "Software"), to deal

src/PHPWebSockets/IStreamContainer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* - - - - - - - - - - - - - BEGIN LICENSE BLOCK - - - - - - - - - - - - -
77
* The MIT License (MIT)
88
*
9-
* Copyright (c) 2020 Kevin Meijer
9+
* Copyright (c) 2021 Kevin Meijer
1010
*
1111
* Permission is hereby granted, free of charge, to any person obtaining a copy
1212
* of this software and associated documentation files (the "Software"), to deal
@@ -76,7 +76,7 @@ public function handleRead() : \Generator;
7676
/**
7777
* Returns the stream object for this connection
7878
*
79-
* @return resource
79+
* @return resource|null
8080
*/
8181
public function getStream();
8282

src/PHPWebSockets/ITaggable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* - - - - - - - - - - - - - BEGIN LICENSE BLOCK - - - - - - - - - - - - -
77
* The MIT License (MIT)
88
*
9-
* Copyright (c) 2020 Kevin Meijer
9+
* Copyright (c) 2021 Kevin Meijer
1010
*
1111
* Permission is hereby granted, free of charge, to any person obtaining a copy
1212
* of this software and associated documentation files (the "Software"), to deal

src/PHPWebSockets/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* - - - - - - - - - - - - - BEGIN LICENSE BLOCK - - - - - - - - - - - - -
77
* The MIT License (MIT)
88
*
9-
* Copyright (c) 2020 Kevin Meijer
9+
* Copyright (c) 2021 Kevin Meijer
1010
*
1111
* Permission is hereby granted, free of charge, to any person obtaining a copy
1212
* of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)