@@ -182,7 +182,8 @@ typedef struct {
182
182
unsigned no_forced_fstat :1 ; /* Use fstat cache even if forced */
183
183
unsigned is_seekable :1 ; /* don't try and seek, if not set */
184
184
unsigned can_poll :1 ;
185
- unsigned _reserved :25 ;
185
+ unsigned seekable_detected :1 ;
186
+ unsigned _reserved :24 ;
186
187
187
188
int lock_flag ; /* stores the lock state */
188
189
zend_string * temp_name ; /* if non-null, this is the path to a temporary file that
@@ -252,6 +253,7 @@ static void _sw_detect_is_seekable(php_stdio_stream_data *self) {
252
253
self -> is_seekable = !(S_ISFIFO (self -> sb .st_mode ) || S_ISCHR (self -> sb .st_mode ));
253
254
self -> is_pipe = S_ISFIFO (self -> sb .st_mode );
254
255
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 ;
255
257
if (self -> can_poll ) {
256
258
swoole_coroutine_socket_create (self -> fd );
257
259
}
@@ -287,7 +289,7 @@ static php_stream *_sw_php_stream_fopen_from_fd(int fd, const char *mode, const
287
289
php_stream * stream = sw_php_stream_fopen_from_fd_int_rel (fd , mode , persistent_id );
288
290
289
291
if (stream ) {
290
- php_stdio_stream_data * self = (php_stdio_stream_data * ) stream -> abstract ;
292
+ php_stdio_stream_data * self = (php_stdio_stream_data * ) stream -> abstract ;
291
293
292
294
_sw_detect_is_seekable (self );
293
295
if (!self -> is_seekable ) {
@@ -328,10 +330,11 @@ static php_stream_size_t sw_php_stdiop_write(php_stream *stream, const char *buf
328
330
}
329
331
bytes_written = _write (data -> fd , buf , (unsigned int )count );
330
332
#else
331
- php_stdio_stream_data * self = (php_stdio_stream_data * ) stream -> abstract ;
332
- ssize_t bytes_written = self -> can_poll ?
333
- swoole_coroutine_write (data -> fd , buf , PLAIN_WRAP_BUF_SIZE (count )) :
334
- write (data -> fd , buf , count );
333
+ php_stdio_stream_data * self = (php_stdio_stream_data * ) stream -> abstract ;
334
+ if (!self -> seekable_detected ) {
335
+ _sw_detect_is_seekable (self );
336
+ }
337
+ ssize_t bytes_written = write (data -> fd , buf , count );
335
338
#endif
336
339
if (bytes_written < 0 ) {
337
340
if (PHP_IS_TRANSIENT_ERROR (errno )) {
@@ -393,18 +396,17 @@ static php_stream_size_t sw_php_stdiop_read(php_stream *stream, char *buf, size_
393
396
}
394
397
}
395
398
#endif
396
- php_stdio_stream_data * self = (php_stdio_stream_data * ) stream -> abstract ;
397
- ret = self -> can_poll ?
398
- swoole_coroutine_read (data -> fd , buf , PLAIN_WRAP_BUF_SIZE (count )) :
399
- read (data -> fd , buf , PLAIN_WRAP_BUF_SIZE (count ));
399
+ php_stdio_stream_data * self = (php_stdio_stream_data * ) stream -> abstract ;
400
+ if (!self -> seekable_detected ) {
401
+ _sw_detect_is_seekable (self );
402
+ }
403
+ ret = read (data -> fd , buf , PLAIN_WRAP_BUF_SIZE (count ));
400
404
401
405
if (ret == (ssize_t ) -1 && errno == EINTR ) {
402
406
/* Read was interrupted, retry once,
403
407
If read still fails, giveup with feof==0
404
408
so script can retry if desired */
405
- ret = self -> can_poll ?
406
- swoole_coroutine_read (data -> fd , buf , PLAIN_WRAP_BUF_SIZE (count )) :
407
- read (data -> fd , buf , PLAIN_WRAP_BUF_SIZE (count ));
409
+ ret = read (data -> fd , buf , PLAIN_WRAP_BUF_SIZE (count ));
408
410
}
409
411
410
412
if (ret < 0 ) {
0 commit comments