@@ 47-50 (lines=4) @@ | ||
44 | ||
45 | $this->_socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); |
|
46 | ||
47 | if ($this->_socket === false){ |
|
48 | $errorCode = socket_last_error($this->_socket); |
|
49 | throw new SocketException(socket_strerror($errorCode), $errorCode); |
|
50 | } |
|
51 | ||
52 | socket_set_option($this->_socket, SOL_TCP, TCP_NODELAY, 1); |
|
53 | ||
@@ 59-63 (lines=5) @@ | ||
56 | ||
57 | $result = socket_connect($this->_socket, $this->_options['host'], $this->_options['port']); |
|
58 | ||
59 | if ($result === false){ |
|
60 | $errorCode = socket_last_error($this->_socket); |
|
61 | //Unable to connect to Cassandra node: {$this->_options['host']}:{$this->_options['port']} |
|
62 | throw new SocketException(socket_strerror($errorCode), $errorCode); |
|
63 | } |
|
64 | } |
|
65 | ||
66 | /** |
|
@@ 82-85 (lines=4) @@ | ||
79 | public function read($length) { |
|
80 | $data = socket_read($this->_socket, $length); |
|
81 | ||
82 | if ($data === false){ |
|
83 | $errorCode = socket_last_error($this->_socket); |
|
84 | throw new SocketException(socket_strerror($errorCode), $errorCode); |
|
85 | } |
|
86 | ||
87 | $remainder = $length - strlen($data); |
|
88 | ||
@@ 92-95 (lines=4) @@ | ||
89 | while($remainder > 0) { |
|
90 | $readData = socket_read($this->_socket, $remainder); |
|
91 | ||
92 | if ($readData === false){ |
|
93 | $errorCode = socket_last_error($this->_socket); |
|
94 | throw new SocketException(socket_strerror($errorCode), $errorCode); |
|
95 | } |
|
96 | ||
97 | $data .= $readData; |
|
98 | $remainder -= strlen($readData); |
|
@@ 112-115 (lines=4) @@ | ||
109 | public function readOnce($length){ |
|
110 | $data = socket_read($this->_socket, $length); |
|
111 | ||
112 | if ($data === false){ |
|
113 | $errorCode = socket_last_error($this->_socket); |
|
114 | throw new SocketException(socket_strerror($errorCode), $errorCode); |
|
115 | } |
|
116 | ||
117 | return $data; |
|
118 | } |
|
@@ 129-132 (lines=4) @@ | ||
126 | do{ |
|
127 | $sentBytes = socket_write($this->_socket, $binary); |
|
128 | ||
129 | if ($sentBytes === false){ |
|
130 | $errorCode = socket_last_error($this->_socket); |
|
131 | throw new SocketException(socket_strerror($errorCode), $errorCode); |
|
132 | } |
|
133 | $binary = substr($binary, $sentBytes); |
|
134 | } |
|
135 | while(!empty($binary)); |