Skip to content

Commit 862ddaf

Browse files
committed
Remove the fread/fwrite/fgets methods from Coroutine\System
1 parent 312ee74 commit 862ddaf

File tree

6 files changed

+1
-309
lines changed

6 files changed

+1
-309
lines changed

ext-src/stubs/php_swoole_coroutine_system.stub.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,5 @@ public static function wait(float $timeout = -1): array|false {}
1313
public static function waitPid(int $pid, float $timeout = -1): array|false {}
1414
public static function waitSignal(int $signo, float $timeout = -1): bool {}
1515
public static function waitEvent(mixed $socket, int $events = SWOOLE_EVENT_READ, float $timeout = -1): int|false {}
16-
/**
17-
* @param resource $handle
18-
* @deprecated
19-
*/
20-
public static function fread($handle, int $length = 0): string|false {}
21-
/**
22-
* @param resource $handle
23-
* @deprecated
24-
*/
25-
public static function fwrite($handle, string $data, int $length = 0): int|false {}
26-
/**
27-
* @param resource $handle
28-
* @deprecated
29-
*/
30-
public static function fgets($handle): string|false {}
3116
}
3217
}

ext-src/stubs/php_swoole_coroutine_system_arginfo.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: ca0f59f1be355a804c432a3ed7243d3306ff53e5 */
2+
* Stub hash: 8c900b375f6550820f059936b75e7a80beb088f5 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Swoole_Coroutine_System_gethostbyname, 0, 1, MAY_BE_FALSE|MAY_BE_STRING)
55
ZEND_ARG_TYPE_INFO(0, domain_name, IS_STRING, 0)
@@ -65,18 +65,3 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Swoole_Coroutine_System_wa
6565
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, events, IS_LONG, 0, "SWOOLE_EVENT_READ")
6666
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_DOUBLE, 0, "-1")
6767
ZEND_END_ARG_INFO()
68-
69-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Swoole_Coroutine_System_fread, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
70-
ZEND_ARG_INFO(0, handle)
71-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 0, "0")
72-
ZEND_END_ARG_INFO()
73-
74-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Swoole_Coroutine_System_fwrite, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
75-
ZEND_ARG_INFO(0, handle)
76-
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
77-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 0, "0")
78-
ZEND_END_ARG_INFO()
79-
80-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Swoole_Coroutine_System_fgets, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
81-
ZEND_ARG_INFO(0, handle)
82-
ZEND_END_ARG_INFO()

ext-src/swoole_coroutine.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ static const zend_function_entry swoole_coroutine_methods[] =
158158
PHP_ME(swoole_coroutine_system, waitPid, arginfo_class_Swoole_Coroutine_System_waitPid, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
159159
PHP_ME(swoole_coroutine_system, waitSignal, arginfo_class_Swoole_Coroutine_System_waitSignal, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
160160
PHP_ME(swoole_coroutine_system, waitEvent, arginfo_class_Swoole_Coroutine_System_waitEvent, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
161-
/* Deprecated file methods */
162-
PHP_ME(swoole_coroutine_system, fread, arginfo_class_Swoole_Coroutine_System_fread, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_DEPRECATED)
163-
PHP_ME(swoole_coroutine_system, fgets, arginfo_class_Swoole_Coroutine_System_fgets, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_DEPRECATED)
164-
PHP_ME(swoole_coroutine_system, fwrite, arginfo_class_Swoole_Coroutine_System_fwrite, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_DEPRECATED)
165161
PHP_FE_END
166162
};
167163
// clang-format on

ext-src/swoole_coroutine_system.cc

Lines changed: 0 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ static const zend_function_entry swoole_coroutine_system_methods[] =
4747
PHP_ME(swoole_coroutine_system, waitPid, arginfo_class_Swoole_Coroutine_System_waitPid, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
4848
PHP_ME(swoole_coroutine_system, waitSignal, arginfo_class_Swoole_Coroutine_System_waitSignal, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
4949
PHP_ME(swoole_coroutine_system, waitEvent, arginfo_class_Swoole_Coroutine_System_waitEvent, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
50-
/* Deprecated file methods */
51-
PHP_ME(swoole_coroutine_system, fread, arginfo_class_Swoole_Coroutine_System_fread, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_DEPRECATED)
52-
PHP_ME(swoole_coroutine_system, fwrite, arginfo_class_Swoole_Coroutine_System_fwrite, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_DEPRECATED)
53-
PHP_ME(swoole_coroutine_system, fgets, arginfo_class_Swoole_Coroutine_System_fgets, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC | ZEND_ACC_DEPRECATED)
5450
PHP_FE_END
5551
};
5652

@@ -76,214 +72,6 @@ PHP_METHOD(swoole_coroutine_system, sleep) {
7672
RETURN_BOOL(System::sleep(seconds) == 0);
7773
}
7874

79-
static void co_socket_read(int fd, zend_long length, INTERNAL_FUNCTION_PARAMETERS) {
80-
php_swoole_check_reactor();
81-
Socket _socket(fd, SW_SOCK_RAW);
82-
83-
zend_string *buf = zend_string_alloc(length + 1, 0);
84-
size_t nbytes = length <= 0 ? SW_BUFFER_SIZE_STD : length;
85-
ssize_t n = _socket.read(ZSTR_VAL(buf), nbytes);
86-
if (n < 0) {
87-
ZVAL_FALSE(return_value);
88-
zend_string_free(buf);
89-
} else if (n == 0) {
90-
ZVAL_EMPTY_STRING(return_value);
91-
zend_string_free(buf);
92-
} else {
93-
ZSTR_VAL(buf)[n] = 0;
94-
ZSTR_LEN(buf) = n;
95-
ZVAL_STR(return_value, buf);
96-
}
97-
_socket.move_fd();
98-
}
99-
100-
static void co_socket_write(int fd, char *str, size_t l_str, INTERNAL_FUNCTION_PARAMETERS) {
101-
php_swoole_check_reactor();
102-
Socket _socket(fd, SW_SOCK_RAW);
103-
104-
ssize_t n = _socket.write(str, l_str);
105-
if (n < 0) {
106-
swoole_set_last_error(errno);
107-
ZVAL_FALSE(return_value);
108-
} else {
109-
ZVAL_LONG(return_value, n);
110-
}
111-
_socket.move_fd();
112-
}
113-
114-
PHP_METHOD(swoole_coroutine_system, fread) {
115-
Coroutine::get_current_safe();
116-
117-
zval *handle;
118-
zend_long length = 0;
119-
120-
ZEND_PARSE_PARAMETERS_START(1, 2)
121-
Z_PARAM_RESOURCE(handle)
122-
Z_PARAM_OPTIONAL
123-
Z_PARAM_LONG(length)
124-
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
125-
126-
int async;
127-
int fd = php_swoole_convert_to_fd_ex(handle, &async);
128-
if (fd < 0) {
129-
RETURN_FALSE;
130-
}
131-
132-
if (async) {
133-
co_socket_read(fd, length, INTERNAL_FUNCTION_PARAM_PASSTHRU);
134-
return;
135-
}
136-
137-
if (length <= 0) {
138-
struct stat file_stat;
139-
if (swoole_coroutine_fstat(fd, &file_stat) < 0) {
140-
swoole_set_last_error(errno);
141-
RETURN_FALSE;
142-
}
143-
off_t _seek = swoole_coroutine_lseek(fd, 0, SEEK_CUR);
144-
if (_seek < 0) {
145-
swoole_set_last_error(errno);
146-
RETURN_FALSE;
147-
}
148-
if (_seek >= file_stat.st_size) {
149-
length = SW_BUFFER_SIZE_STD;
150-
} else {
151-
length = file_stat.st_size - _seek;
152-
}
153-
}
154-
155-
zend_string *buf = zend_string_alloc(length, 0);
156-
ssize_t ret = -1;
157-
swoole_trace("fd=%d, length=" ZEND_LONG_FMT, fd, length);
158-
php_swoole_check_reactor();
159-
bool async_success = swoole::coroutine::async([&]() {
160-
while (1) {
161-
ret = read(fd, buf->val, length);
162-
if (ret < 0 && errno == EINTR) {
163-
continue;
164-
}
165-
break;
166-
}
167-
});
168-
169-
if (async_success && ret >= 0) {
170-
buf->len = ret;
171-
buf->val[buf->len] = 0;
172-
RETURN_STR(buf);
173-
} else {
174-
zend_string_release(buf);
175-
RETURN_FALSE;
176-
}
177-
}
178-
179-
PHP_METHOD(swoole_coroutine_system, fgets) {
180-
Coroutine::get_current_safe();
181-
182-
zval *handle;
183-
php_stream *stream;
184-
185-
ZEND_PARSE_PARAMETERS_START(1, 1)
186-
Z_PARAM_RESOURCE(handle)
187-
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
188-
189-
int async;
190-
int fd = php_swoole_convert_to_fd_ex(handle, &async);
191-
if (fd < 0) {
192-
RETURN_FALSE;
193-
}
194-
195-
if (async == 1) {
196-
php_swoole_fatal_error(E_WARNING, "only support file resources");
197-
RETURN_FALSE;
198-
}
199-
200-
php_stream_from_res(stream, Z_RES_P(handle));
201-
202-
FILE *file;
203-
if (stream->stdiocast) {
204-
file = stream->stdiocast;
205-
} else {
206-
if (php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void **) &file, 1) != SUCCESS || file == nullptr) {
207-
RETURN_FALSE;
208-
}
209-
}
210-
211-
if (stream->readbuf == nullptr) {
212-
stream->readbuflen = stream->chunk_size;
213-
stream->readbuf = (uchar *) emalloc(stream->chunk_size);
214-
}
215-
216-
if (!stream->readbuf) {
217-
RETURN_FALSE;
218-
}
219-
220-
int ret = 0;
221-
swoole_trace("fd=%d, length=%ld", fd, stream->readbuflen);
222-
php_swoole_check_reactor();
223-
bool async_success = swoole::coroutine::async([&]() {
224-
char *data = fgets((char *) stream->readbuf, stream->readbuflen, file);
225-
if (data == nullptr) {
226-
ret = -1;
227-
stream->eof = 1;
228-
}
229-
});
230-
231-
if (async_success && ret != -1) {
232-
ZVAL_STRING(return_value, (char *) stream->readbuf);
233-
} else {
234-
ZVAL_FALSE(return_value);
235-
}
236-
}
237-
238-
PHP_METHOD(swoole_coroutine_system, fwrite) {
239-
Coroutine::get_current_safe();
240-
241-
zval *handle;
242-
char *str;
243-
size_t l_str;
244-
zend_long length = 0;
245-
246-
ZEND_PARSE_PARAMETERS_START(2, 3)
247-
Z_PARAM_RESOURCE(handle)
248-
Z_PARAM_STRING(str, l_str)
249-
Z_PARAM_OPTIONAL
250-
Z_PARAM_LONG(length)
251-
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
252-
253-
int async;
254-
int fd = php_swoole_convert_to_fd_ex(handle, &async);
255-
if (fd < 0) {
256-
RETURN_FALSE;
257-
}
258-
if (length <= 0 || (size_t) length > l_str) {
259-
length = l_str;
260-
}
261-
if (async) {
262-
co_socket_write(fd, str, length, INTERNAL_FUNCTION_PARAM_PASSTHRU);
263-
return;
264-
}
265-
266-
zend::CharPtr buf(str, length);
267-
ssize_t ret = -1;
268-
swoole_trace("fd=%d, length=" ZEND_LONG_FMT, fd, length);
269-
php_swoole_check_reactor();
270-
bool async_success = swoole::coroutine::async([&]() {
271-
while (1) {
272-
ret = write(fd, buf.get(), length);
273-
if (ret < 0 && errno == EINTR) {
274-
continue;
275-
}
276-
break;
277-
}
278-
});
279-
280-
if (async_success && ret >= 0) {
281-
ZVAL_LONG(return_value, ret);
282-
} else {
283-
ZVAL_FALSE(return_value);
284-
}
285-
}
286-
28775
PHP_METHOD(swoole_coroutine_system, readFile) {
28876
char *filename;
28977
size_t l_filename;

tests/swoole_coroutine_system/fread.phpt

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/swoole_coroutine_system/fwrite.phpt

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)