Skip to content

Commit 1eef4f2

Browse files
committed
Miscellaneous cleanup
1 parent a8cb1d2 commit 1eef4f2

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

ext/openssl/xp_ssl.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ static int handle_ssl_error(php_stream *stream, int nr_bytes, zend_bool is_init
174174
return retry;
175175
}
176176

177-
static size_t php_openssl_sockop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
177+
static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
178178
{
179-
return php_openssl_sockop_io( 0, stream, buf, count TSRMLS_CC);
179+
return php_openssl_sockop_io(1, stream, buf, count TSRMLS_CC);
180180
}
181181

182-
static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
182+
static size_t php_openssl_sockop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
183183
{
184-
return php_openssl_sockop_io( 1, stream, buf, count TSRMLS_CC);
184+
return php_openssl_sockop_io(0, stream, (char*)buf, count TSRMLS_CC);
185185
}
186186

187187
/**
@@ -194,15 +194,15 @@ static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t coun
194194
static size_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, size_t count TSRMLS_DC)
195195
{
196196
php_openssl_netstream_data_t *sslsock = (php_openssl_netstream_data_t*)stream->abstract;
197-
int nr_bytes = 0;
197+
int nr_bytes = 0;
198198

199-
/* Only do this if SSL is active. */
199+
/* Only do this if SSL is active. */
200200
if (sslsock->ssl_active) {
201201
int retry = 1;
202-
struct timeval start_time,
203-
*timeout;
204-
int blocked = sslsock->s.is_blocked,
205-
has_timeout = 0;
202+
struct timeval start_time;
203+
struct timeval *timeout;
204+
int blocked = sslsock->s.is_blocked;
205+
int has_timeout = 0;
206206

207207
/* Begin by making the socket non-blocking. This allows us to check the timeout. */
208208
if (SUCCESS == php_set_sock_blocking(sslsock->s.socket, 0 TSRMLS_CC)) {
@@ -216,7 +216,7 @@ static size_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, siz
216216
/* gettimeofday is not monotonic; using it here is not strictly correct */
217217
if (has_timeout) {
218218
gettimeofday(&start_time, NULL);
219-
}
219+
}
220220

221221
/* Main IO loop. */
222222
do {
@@ -263,7 +263,7 @@ static size_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, siz
263263
if (errno == EAGAIN && err == SSL_ERROR_WANT_READ && read) {
264264
retry = 1;
265265
}
266-
if (errno == EAGAIN && SSL_ERROR_WANT_WRITE && read == 0) {
266+
if (errno == EAGAIN && SSL_ERROR_WANT_WRITE && read == 0) {
267267
retry = 1;
268268
}
269269

@@ -289,18 +289,20 @@ static size_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, siz
289289
int err = SSL_get_error(sslsock->ssl_handle, nr_bytes );
290290

291291
/* If we didn't get any error, then let's return it to PHP. */
292-
if (err == SSL_ERROR_NONE)
293-
break;
292+
if (err == SSL_ERROR_NONE) {
293+
break;
294+
}
294295

295296
/* Otherwise, we need to wait again (up to time_left or we get an error) */
296-
if (blocked)
297+
if (blocked) {
297298
if (read) {
298299
php_pollfd_for(sslsock->s.socket, (err == SSL_ERROR_WANT_WRITE) ?
299300
(POLLOUT|POLLPRI) : (POLLIN|POLLPRI), has_timeout ? &left_time : NULL);
300301
} else {
301302
php_pollfd_for(sslsock->s.socket, (err == SSL_ERROR_WANT_READ) ?
302303
(POLLIN|POLLPRI) : (POLLOUT|POLLPRI), has_timeout ? &left_time : NULL);
303304
}
305+
}
304306
}
305307
/* Finally, we keep going until we got data, and an SSL_ERROR_NONE, unless we had an error. */
306308
} while (retry);
@@ -312,21 +314,19 @@ static size_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, siz
312314

313315
/* And if we were originally supposed to be blocking, let's reset the socket to that. */
314316
if (blocked) {
315-
php_set_sock_blocking(sslsock->s.socket, 1 TSRMLS_CC);
316-
sslsock->s.is_blocked = 1;
317-
}
318-
} else {
319-
/*
320-
* This block is if we had no timeout... We will just sit and wait forever on the IO operation.
321-
*/
322-
if (read) {
323-
nr_bytes = php_stream_socket_ops.read(stream, buf, count TSRMLS_CC);
324-
} else {
325-
nr_bytes = php_stream_socket_ops.write(stream, buf, count TSRMLS_CC);
317+
php_set_sock_blocking(sslsock->s.socket, 1 TSRMLS_CC);
318+
sslsock->s.is_blocked = 1;
319+
}
320+
} else {
321+
/* This block is if we had no timeout... We will just sit and wait forever on the IO operation. */
322+
if (read) {
323+
nr_bytes = php_stream_socket_ops.read(stream, buf, count TSRMLS_CC);
324+
} else {
325+
nr_bytes = php_stream_socket_ops.write(stream, buf, count TSRMLS_CC);
326+
}
326327
}
327-
}
328328

329-
/* PHP doesn't expect a negative return. */
329+
/* PHP doesn't expect a negative return. */
330330
if (nr_bytes < 0) {
331331
nr_bytes = 0;
332332
}

0 commit comments

Comments
 (0)