Skip to content

Commit a3c76b1

Browse files
authored
Fix framework tests, revert read/write asyncio impl (#5830)
* fix tests --filter=[framework] * revert --filter=[framework]
1 parent 03e77c0 commit a3c76b1

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/coroutine/hook.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,11 @@ ssize_t swoole_coroutine_read(int sockfd, void *buf, size_t count) {
461461

462462
#ifdef SW_USE_ASYNC
463463
ssize_t ret = -1;
464-
async([&]() { ret = read(sockfd, buf, count); });
464+
NetSocket sock = {};
465+
sock.fd = sockfd;
466+
sock.nonblock = 1;
467+
sock.read_timeout = -1;
468+
async([&]() { ret = sock.read_sync(buf, count); });
465469
return ret;
466470
#else
467471
return Iouring::read(sockfd, buf, count);
@@ -480,7 +484,11 @@ ssize_t swoole_coroutine_write(int sockfd, const void *buf, size_t count) {
480484

481485
#ifdef SW_USE_ASYNC
482486
ssize_t ret = -1;
483-
async([&]() { ret = write(sockfd, buf, count); });
487+
NetSocket sock = {};
488+
sock.fd = sockfd;
489+
sock.nonblock = 1;
490+
sock.write_timeout = -1;
491+
async([&]() { ret = sock.write_sync(buf, count); });
484492
return ret;
485493
#else
486494
return Iouring::write(sockfd, buf, count);

src/network/socket.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ void Socket::free() {
472472
delete out_buffer;
473473

474474
if (swoole_event_is_available()) {
475-
if (!removed) {
475+
if (fd != -1 && !removed) {
476476
swoole_event_del(this);
477477
}
478478
swoole_event_defer(socket_free_defer, this);

thirdparty/php/streams/plain_wrapper.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ typedef struct {
182182
unsigned no_forced_fstat:1; /* Use fstat cache even if forced */
183183
unsigned is_seekable:1; /* don't try and seek, if not set */
184184
unsigned can_poll:1;
185-
unsigned seekable_detected:1;
186-
unsigned _reserved:24;
185+
unsigned _reserved:25;
187186

188187
int lock_flag; /* stores the lock state */
189188
zend_string *temp_name; /* if non-null, this is the path to a temporary file that
@@ -253,7 +252,6 @@ static void _sw_detect_is_seekable(php_stdio_stream_data *self) {
253252
self->is_seekable = !(S_ISFIFO(self->sb.st_mode) || S_ISCHR(self->sb.st_mode));
254253
self->is_pipe = S_ISFIFO(self->sb.st_mode);
255254
self->can_poll = S_ISFIFO(self->sb.st_mode) || S_ISSOCK(self->sb.st_mode) || S_ISCHR(self->sb.st_mode);
256-
self->seekable_detected = 1;
257255
if (self->can_poll) {
258256
swoole_coroutine_socket_create(self->fd);
259257
}
@@ -331,9 +329,6 @@ static php_stream_size_t sw_php_stdiop_write(php_stream *stream, const char *buf
331329
bytes_written = _write(data->fd, buf, (unsigned int)count);
332330
#else
333331
php_stdio_stream_data *self = (php_stdio_stream_data *) stream->abstract;
334-
if (!self->seekable_detected) {
335-
_sw_detect_is_seekable(self);
336-
}
337332
ssize_t bytes_written = write(data->fd, buf, count);
338333
#endif
339334
if (bytes_written < 0) {
@@ -397,9 +392,6 @@ static php_stream_size_t sw_php_stdiop_read(php_stream *stream, char *buf, size_
397392
}
398393
#endif
399394
php_stdio_stream_data *self = (php_stdio_stream_data *) stream->abstract;
400-
if (!self->seekable_detected) {
401-
_sw_detect_is_seekable(self);
402-
}
403395
ret = read(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count));
404396

405397
if (ret == (ssize_t) -1 && errno == EINTR) {

0 commit comments

Comments
 (0)