From acc005599a671b0553cb2df5e1c73f751a69fae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E5=A4=A9=E5=B3=B0-Rango?= Date: Mon, 18 May 2020 16:51:01 +0800 Subject: [PATCH] add const modifier (#3326) * add const modifier * fix tests --- include/client.h | 8 ++++---- include/http.h | 4 ++-- include/http2.h | 2 +- include/mqtt.h | 2 +- include/server.h | 4 ++-- include/swoole.h | 39 ++++++++++++++++++------------------ include/websocket.h | 4 ++-- php_swoole.h | 4 ++-- src/core/base.cc | 2 +- src/core/channel.cc | 4 ++-- src/core/string.cc | 4 ++-- src/memory/shared_memory.cc | 2 +- src/network/client.cc | 4 ++-- src/network/stream.cc | 6 +++--- src/os/process_pool.cc | 6 +++--- src/os/thread_pool.cc | 4 ++-- src/pipe/base.cc | 4 ++-- src/pipe/eventfd.cc | 4 ++-- src/pipe/unix_socket.cc | 4 ++-- src/protocol/base.cc | 2 +- src/protocol/http.cc | 4 ++-- src/protocol/http2.cc | 2 +- src/protocol/mqtt.cc | 4 ++-- src/protocol/websocket.cc | 6 +++--- src/server/base.cc | 2 +- src/server/master.cc | 2 +- src/server/reactor_thread.cc | 8 ++++---- src/server/worker.cc | 6 +++--- swoole_client.cc | 2 +- swoole_process_pool.cc | 2 +- swoole_server_port.cc | 2 +- swoole_socket_coro.cc | 2 +- 32 files changed, 77 insertions(+), 78 deletions(-) diff --git a/include/client.h b/include/client.h index 81610fbf7da..a03aac58d44 100644 --- a/include/client.h +++ b/include/client.h @@ -136,7 +136,7 @@ typedef struct _swClient void (*onConnect)(struct _swClient *cli); void (*onError)(struct _swClient *cli); - void (*onReceive)(struct _swClient *cli, char *data, uint32_t length); + void (*onReceive)(struct _swClient *cli, const char *data, uint32_t length); void (*onClose)(struct _swClient *cli); void (*onBufferFull)(struct _swClient *cli); void (*onBufferEmpty)(struct _swClient *cli); @@ -166,12 +166,12 @@ typedef struct _swStream swString *buffer; uint8_t cancel; void *private_data; - void (*response)(struct _swStream *stream, char *data, uint32_t length); + void (*response)(struct _swStream *stream, const char *data, uint32_t length); swClient client; } swStream; -swStream* swStream_new(char *dst_host, int dst_port, enum swSocket_type type); -int swStream_send(swStream *stream, char *data, size_t length); +swStream* swStream_new(const char *dst_host, int dst_port, enum swSocket_type type); +int swStream_send(swStream *stream, const char *data, size_t length); void swStream_set_protocol(swProtocol *protocol); void swStream_set_max_length(swStream *stream, uint32_t max_length); int swStream_recv_blocking(swSocket *sock, void *__buf, size_t __len); diff --git a/include/http.h b/include/http.h index 8f5c03a3d90..ce0c1caa8d5 100644 --- a/include/http.h +++ b/include/http.h @@ -136,9 +136,9 @@ int swHttpRequest_has_expect_header(swHttpRequest *request); #endif #ifdef SW_USE_HTTP2 -ssize_t swHttpMix_get_package_length(swProtocol *protocol, swSocket *conn, char *data, uint32_t length); +ssize_t swHttpMix_get_package_length(swProtocol *protocol, swSocket *conn, const char *data, uint32_t length); uint8_t swHttpMix_get_package_length_size(swSocket *conn); -int swHttpMix_dispatch_frame(swProtocol *protocol, swSocket *conn, char *data, uint32_t length); +int swHttpMix_dispatch_frame(swProtocol *protocol, swSocket *conn, const char *data, uint32_t length); #endif SW_EXTERN_C_END diff --git a/include/http2.h b/include/http2.h index e3eddf0c2ac..8c050500453 100644 --- a/include/http2.h +++ b/include/http2.h @@ -145,7 +145,7 @@ static sw_inline ssize_t swHttp2_get_length(const char *buf) return (((uint8_t) buf[0]) << 16) + (((uint8_t) buf[1]) << 8) + (uint8_t) buf[2]; } -ssize_t swHttp2_get_frame_length(swProtocol *protocol, swSocket *conn, char *buf, uint32_t length); +ssize_t swHttp2_get_frame_length(swProtocol *protocol, swSocket *conn, const char *buf, uint32_t length); int swHttp2_send_setting_frame(swProtocol *protocol, swSocket *conn); const char* swHttp2_get_type(int type); int swHttp2_get_type_color(int type); diff --git a/include/mqtt.h b/include/mqtt.h index c58613ea53b..9d08881b37a 100644 --- a/include/mqtt.h +++ b/include/mqtt.h @@ -61,7 +61,7 @@ typedef struct #define SETQOS(HDR, Q) (HDR | ((Q) << 1)) #define SETDUP(HDR, D) (HDR | ((D) << 3)) -ssize_t swMqtt_get_package_length(swProtocol *protocol, swSocket *conn, char *data, uint32_t size); +ssize_t swMqtt_get_package_length(swProtocol *protocol, swSocket *conn, const char *data, uint32_t size); SW_EXTERN_C_END diff --git a/include/server.h b/include/server.h index c87d8926e28..cf2b98f88c7 100644 --- a/include/server.h +++ b/include/server.h @@ -1061,8 +1061,8 @@ void swReactorThread_set_protocol(swServer *serv, swReactor *reactor); void swReactorThread_join(swServer *serv); void swReactorThread_free(swServer *serv); int swReactorThread_close(swReactor *reactor, swSocket *_socket); -int swReactorThread_dispatch(swProtocol *proto, swSocket *_socket, char *data, uint32_t length); -int swReactorThread_send2worker(swServer *serv, swWorker *worker, void *data, size_t len); +int swReactorThread_dispatch(swProtocol *proto, swSocket *_socket, const char *data, uint32_t length); +int swReactorThread_send2worker(swServer *serv, swWorker *worker, const void *data, size_t len); int swReactorProcess_create(swServer *serv); int swReactorProcess_start(swServer *serv); diff --git a/include/swoole.h b/include/swoole.h index 2a25ae3227c..8e45a5c3301 100644 --- a/include/swoole.h +++ b/include/swoole.h @@ -844,12 +844,12 @@ typedef struct _swProtocol uint16_t real_header_length; uint16_t ext_flags; - int (*onPackage)(struct _swProtocol *, swSocket *, char *, uint32_t); - ssize_t (*get_package_length)(struct _swProtocol *, swSocket *, char *, uint32_t); + int (*onPackage)(struct _swProtocol *, swSocket *, const char *, uint32_t); + ssize_t (*get_package_length)(struct _swProtocol *, swSocket *, const char *, uint32_t); uint8_t (*get_package_length_size)(swSocket *); } swProtocol; -typedef ssize_t (*swProtocol_length_function)(struct _swProtocol *, swSocket *, char *, uint32_t); +typedef ssize_t (*swProtocol_length_function)(struct _swProtocol *, swSocket *, const char *, uint32_t); //------------------------------String-------------------------------- #define swoole_tolower(c) (uchar) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c) #define swoole_toupper(c) (uchar) ((c >= 'a' && c <= 'z') ? (c & ~0x20) : c) @@ -885,10 +885,10 @@ swString *swString_dup(const char *src_str, size_t length); swString *swString_dup2(swString *src); int swString_repeat(swString *src, const char *data, size_t len, size_t n); void swString_print(swString *str); -int swString_append(swString *str, swString *append_str); +int swString_append(swString *str, const swString *append_str); int swString_append_ptr(swString *str, const char *append_str, size_t length); int swString_write(swString *str, off_t offset, swString *write_str); -int swString_write_ptr(swString *str, off_t offset, char *write_str, size_t length); +int swString_write_ptr(swString *str, off_t offset, const char *write_str, size_t length); int swString_extend(swString *str, size_t new_size); char* swString_alloc(swString *str, size_t __size); @@ -1025,7 +1025,7 @@ typedef struct _swDgramPacket typedef struct _swSendData { swDataHead info; - char *data; + const char *data; } swSendData; typedef struct @@ -1050,7 +1050,7 @@ typedef struct _swPipe swSocket *worker_socket; int (*read)(struct _swPipe *, void *recv, int length); - int (*write)(struct _swPipe *, void *send, int length); + int (*write)(struct _swPipe *, const void *send, int length); swSocket* (*getSocket)(struct _swPipe *, int master); int (*close)(struct _swPipe *); } swPipe; @@ -1223,7 +1223,7 @@ typedef struct _swShareMemory_mmap void *mem; } swShareMemory; -void *swShareMemory_mmap_create(swShareMemory *object, size_t size, char *mapfile); +void *swShareMemory_mmap_create(swShareMemory *object, size_t size, const char *mapfile); void *swShareMemory_sysv_create(swShareMemory *object, size_t size, int key); int swShareMemory_sysv_free(swShareMemory *object, int rm); int swShareMemory_mmap_free(swShareMemory *object); @@ -1379,12 +1379,12 @@ const char* swLog_get_file(); void swLog_set_date_with_microseconds(uchar enable); //----------------------Tool Function--------------------- -uint64_t swoole_hash_key(char *str, int str_len); +uint64_t swoole_hash_key(const char *str, int str_len); uint32_t swoole_common_multiple(uint32_t u, uint32_t v); uint32_t swoole_common_divisor(uint32_t u, uint32_t v); -extern void swoole_sha1(const char *str, int _len, unsigned char *digest); -extern void swoole_sha256(const char *str, int _len, unsigned char *digest); +extern void swoole_sha1(const char *str, int _len, uchar *digest); +extern void swoole_sha256(const char *str, int _len, uchar *digest); static sw_inline uint16_t swoole_swap_endian16(uint16_t x) { @@ -1631,7 +1631,6 @@ int swSocket_sendfile_sync(int sock, const char *filename, off_t offset, size_t ssize_t swSocket_write_blocking(swSocket *sock, const void *__data, size_t __len); ssize_t swSocket_recv_blocking(swSocket *sock, void *__data, size_t __len, int flags); - static sw_inline int swSocket_error(int err) { switch (err) @@ -2015,7 +2014,7 @@ struct _swProcessPool int (*onTask)(struct _swProcessPool *pool, swEventData *task); void (*onWorkerStart)(struct _swProcessPool *pool, int worker_id); - void (*onMessage)(struct _swProcessPool *pool, char *data, uint32_t length); + void (*onMessage)(struct _swProcessPool *pool, const char *data, uint32_t length); void (*onWorkerStop)(struct _swProcessPool *pool, int worker_id); int (*main_loop)(struct _swProcessPool *pool, swWorker *worker); @@ -2242,8 +2241,8 @@ int swReactorSelect_create(swReactor *reactor); /*----------------------------Process Pool-------------------------------*/ int swProcessPool_create(swProcessPool *pool, uint32_t worker_num, key_t msgqueue_key, int ipc_mode); -int swProcessPool_create_unix_socket(swProcessPool *pool, char *socket_file, int blacklog); -int swProcessPool_create_tcp_socket(swProcessPool *pool, char *host, int port, int blacklog); +int swProcessPool_create_unix_socket(swProcessPool *pool, const char *socket_file, int blacklog); +int swProcessPool_create_tcp_socket(swProcessPool *pool, const char *host, int port, int blacklog); int swProcessPool_set_protocol(swProcessPool *pool, int task_protocol, uint32_t max_packet_size); void swProcessPool_set_max_request(swProcessPool *pool, uint32_t max_request, uint32_t max_request_grace); int swProcessPool_wait(swProcessPool *pool); @@ -2251,7 +2250,7 @@ int swProcessPool_start(swProcessPool *pool); void swProcessPool_shutdown(swProcessPool *pool); pid_t swProcessPool_spawn(swProcessPool *pool, swWorker *worker); int swProcessPool_dispatch(swProcessPool *pool, swEventData *data, int *worker_id); -int swProcessPool_response(swProcessPool *pool, char *data, int length); +int swProcessPool_response(swProcessPool *pool, const char *data, int length); int swProcessPool_dispatch_blocking(swProcessPool *pool, swEventData *data, int *dst_worker_id); int swProcessPool_add_worker(swProcessPool *pool, swWorker *worker); int swProcessPool_del_worker(swProcessPool *pool, swWorker *worker); @@ -2317,9 +2316,9 @@ swChannel* swChannel_new(size_t size, size_t maxlen, int flag); #define swChannel_empty(ch) (ch->num == 0) #define swChannel_full(ch) ((ch->head == ch->tail && ch->tail_tag != ch->head_tag) || (ch->bytes + sizeof(int) * ch->num == ch->size)) int swChannel_pop(swChannel *object, void *out, int buffer_length); -int swChannel_push(swChannel *object, void *in, int data_length); +int swChannel_push(swChannel *object, const void *in, int data_length); int swChannel_out(swChannel *object, void *out, int buffer_length); -int swChannel_in(swChannel *object, void *in, int data_length); +int swChannel_in(swChannel *object, const void *in, int data_length); int swChannel_peek(swChannel *object, void *out, int buffer_length); int swChannel_wait(swChannel *object); int swChannel_notify(swChannel *object); @@ -2370,13 +2369,13 @@ struct _swThread swThreadPool *pool; }; -int swThreadPool_dispatch(swThreadPool *pool, void *task, int task_len); +int swThreadPool_dispatch(swThreadPool *pool, const void *task, int task_len); int swThreadPool_create(swThreadPool *pool, int max_num); int swThreadPool_run(swThreadPool *pool); int swThreadPool_free(swThreadPool *pool); //--------------------------------protocol------------------------------ -ssize_t swProtocol_get_package_length(swProtocol *protocol, swSocket *conn, char *data, uint32_t size); +ssize_t swProtocol_get_package_length(swProtocol *protocol, swSocket *conn, const char *data, uint32_t size); int swProtocol_recv_check_length(swProtocol *protocol, swSocket *conn, swString *buffer); int swProtocol_recv_check_eof(swProtocol *protocol, swSocket *conn, swString *buffer); diff --git a/include/websocket.h b/include/websocket.h index e634a122bdf..bb1b20efdde 100644 --- a/include/websocket.h +++ b/include/websocket.h @@ -173,8 +173,8 @@ void swWebSocket_decode(swWebSocket_frame *frame, swString *data); int swWebSocket_pack_close_frame(swString *buffer, int code, char* reason, size_t length, uint8_t flags); void swWebSocket_print_frame(swWebSocket_frame *frame); -ssize_t swWebSocket_get_package_length(swProtocol *protocol, swSocket *conn, char *data, uint32_t length); -int swWebSocket_dispatch_frame(swProtocol *protocol, swSocket *conn, char *data, uint32_t length); +ssize_t swWebSocket_get_package_length(swProtocol *protocol, swSocket *conn, const char *data, uint32_t length); +int swWebSocket_dispatch_frame(swProtocol *protocol, swSocket *conn, const char *data, uint32_t length); SW_EXTERN_C_END diff --git a/php_swoole.h b/php_swoole.h index dba959c81ad..eff9209b194 100644 --- a/php_swoole.h +++ b/php_swoole.h @@ -347,8 +347,8 @@ php_socket *swoole_convert_to_socket(int sock); void swoole_php_socket_free(zval *zsocket); #endif -ssize_t php_swoole_length_func(swProtocol *protocol, swSocket *_socket, char *data, uint32_t length); -int php_swoole_client_onPackage(swConnection *conn, char *data, uint32_t length); +ssize_t php_swoole_length_func(swProtocol *protocol, swSocket *_socket, const char *data, uint32_t length); +int php_swoole_client_onPackage(swConnection *conn, const char *data, uint32_t length); zend_bool php_swoole_signal_isset_handler(int signo); ZEND_BEGIN_MODULE_GLOBALS(swoole) diff --git a/src/core/base.cc b/src/core/base.cc index 7ecf12bc5da..6440a1f995b 100644 --- a/src/core/base.cc +++ b/src/core/base.cc @@ -254,7 +254,7 @@ pid_t swoole_fork(int flags) return pid; } -uint64_t swoole_hash_key(char *str, int str_len) +uint64_t swoole_hash_key(const char *str, int str_len) { uint64_t hash = 5381; int c, i = 0; diff --git a/src/core/channel.cc b/src/core/channel.cc index 62c9eeff3ca..47284fdfaa4 100644 --- a/src/core/channel.cc +++ b/src/core/channel.cc @@ -85,7 +85,7 @@ swChannel* swChannel_new(size_t size, size_t maxlen, int flags) /** * push data(no lock) */ -int swChannel_in(swChannel *object, void *in, int data_length) +int swChannel_in(swChannel *object, const void *in, int data_length) { assert(data_length <= object->maxlen); if (swChannel_full(object)) @@ -190,7 +190,7 @@ int swChannel_notify(swChannel *object) /** * push data (lock) */ -int swChannel_push(swChannel *object, void *in, int data_length) +int swChannel_push(swChannel *object, const void *in, int data_length) { assert(object->flag & SW_CHAN_LOCK); object->lock.lock(&object->lock); diff --git a/src/core/string.cc b/src/core/string.cc index d401ab119e7..cad5db7b4db 100644 --- a/src/core/string.cc +++ b/src/core/string.cc @@ -76,7 +76,7 @@ swString *swString_dup(const char *src_str, size_t length) return str; } -int swString_append(swString *str, swString *append_str) +int swString_append(swString *str, const swString *append_str) { size_t new_size = str->length + append_str->length; if (new_size > str->size) @@ -147,7 +147,7 @@ int swString_write(swString *str, off_t offset, swString *write_str) return SW_OK; } -int swString_write_ptr(swString *str, off_t offset, char *write_str, size_t length) +int swString_write_ptr(swString *str, off_t offset, const char *write_str, size_t length) { size_t new_length = offset + length; if (new_length > str->size) diff --git a/src/memory/shared_memory.cc b/src/memory/shared_memory.cc index c457d40866e..80ec16b4a53 100644 --- a/src/memory/shared_memory.cc +++ b/src/memory/shared_memory.cc @@ -86,7 +86,7 @@ void* sw_shm_realloc(void *ptr, size_t new_size) } } -void *swShareMemory_mmap_create(swShareMemory *object, size_t size, char *mapfile) +void *swShareMemory_mmap_create(swShareMemory *object, size_t size, const char *mapfile) { void *mem; int tmpfd = -1; diff --git a/src/network/client.cc b/src/network/client.cc index d6931f85cf2..4eedf4b0d8d 100644 --- a/src/network/client.cc +++ b/src/network/client.cc @@ -40,7 +40,7 @@ static int swClient_onWrite(swReactor *reactor, swEvent *event); static int swClient_onError(swReactor *reactor, swEvent *event); static void swClient_onTimeout(swTimer *timer, swTimer_node *tnode); static void swClient_onResolveCompleted(swAio_event *event); -static int swClient_onPackage(swProtocol *proto, swSocket *conn, char *data, uint32_t length); +static int swClient_onPackage(swProtocol *proto, swSocket *conn, const char *data, uint32_t length); static sw_inline void execute_onConnect(swClient *cli) { @@ -1068,7 +1068,7 @@ static int swClient_https_proxy_handshake(swClient *cli) } #endif -static int swClient_onPackage(swProtocol *proto, swSocket *conn, char *data, uint32_t length) +static int swClient_onPackage(swProtocol *proto, swSocket *conn, const char *data, uint32_t length) { swClient *cli = (swClient *) conn->object; cli->onReceive(cli, data, length); diff --git a/src/network/stream.cc b/src/network/stream.cc index 9d0a07ca671..05027065248 100644 --- a/src/network/stream.cc +++ b/src/network/stream.cc @@ -45,7 +45,7 @@ static void swStream_onError(swClient *cli) swStream_free((swStream *) cli->object); } -static void swStream_onReceive(swClient *cli, char *data, uint32_t length) +static void swStream_onReceive(swClient *cli, const char *data, uint32_t length) { swStream *stream = (swStream*) cli->object; if (length == 4) @@ -76,7 +76,7 @@ static void swStream_free(swStream *stream) sw_free(stream); } -swStream* swStream_new(char *dst_host, int dst_port, enum swSocket_type type) +swStream* swStream_new(const char *dst_host, int dst_port, enum swSocket_type type) { swStream *stream = (swStream*) sw_malloc(sizeof(swStream)); if (!stream) @@ -129,7 +129,7 @@ void swStream_set_max_length(swStream *stream, uint32_t max_length) stream->client.protocol.package_max_length = max_length; } -int swStream_send(swStream *stream, char *data, size_t length) +int swStream_send(swStream *stream, const char *data, size_t length) { if (stream->buffer == NULL) { diff --git a/src/os/process_pool.cc b/src/os/process_pool.cc index dc6fcae9b7b..eedf47a59ce 100644 --- a/src/os/process_pool.cc +++ b/src/os/process_pool.cc @@ -155,7 +155,7 @@ int swProcessPool_create(swProcessPool *pool, uint32_t worker_num, key_t msgqueu return SW_OK; } -int swProcessPool_create_unix_socket(swProcessPool *pool, char *socket_file, int blacklog) +int swProcessPool_create_unix_socket(swProcessPool *pool, const char *socket_file, int blacklog) { if (pool->ipc_mode != SW_IPC_SOCKET) { @@ -175,7 +175,7 @@ int swProcessPool_create_unix_socket(swProcessPool *pool, char *socket_file, int return SW_OK; } -int swProcessPool_create_tcp_socket(swProcessPool *pool, char *host, int port, int blacklog) +int swProcessPool_create_tcp_socket(swProcessPool *pool, const char *host, int port, int blacklog) { if (pool->ipc_mode != SW_IPC_SOCKET) { @@ -247,7 +247,7 @@ static sw_inline int swProcessPool_schedule(swProcessPool *pool) return target_worker_id; } -int swProcessPool_response(swProcessPool *pool, char *data, int length) +int swProcessPool_response(swProcessPool *pool, const char *data, int length) { if (pool->stream == nullptr || pool->stream->last_connection == nullptr || pool->stream->response_buffer == nullptr) { diff --git a/src/os/thread_pool.cc b/src/os/thread_pool.cc index 7f9dea4c139..9e996b8a747 100644 --- a/src/os/thread_pool.cc +++ b/src/os/thread_pool.cc @@ -68,7 +68,7 @@ int swThreadPool_create(swThreadPool *pool, int thread_num) return SW_OK; } -int swThreadPool_dispatch(swThreadPool *pool, void *task, int task_len) +int swThreadPool_dispatch(swThreadPool *pool, const void *task, int task_len) { int ret; @@ -76,7 +76,7 @@ int swThreadPool_dispatch(swThreadPool *pool, void *task, int task_len) #ifdef SW_THREADPOOL_USE_CHANNEL ret = swChannel_in(pool->chan, task, task_len); #else - ret = swRingQueue_push(&pool->queue, task); + ret = swRingQueue_push(&pool->queue, (char*) task); #endif pool->cond.unlock(&pool->cond); diff --git a/src/pipe/base.cc b/src/pipe/base.cc index c810e2a7ac1..76d767e6c82 100644 --- a/src/pipe/base.cc +++ b/src/pipe/base.cc @@ -17,7 +17,7 @@ #include "swoole.h" static int swPipeBase_read(swPipe *p, void *data, int length); -static int swPipeBase_write(swPipe *p, void *data, int length); +static int swPipeBase_write(swPipe *p, const void *data, int length); static int swPipeBase_close(swPipe *p); typedef struct _swPipeBase @@ -108,7 +108,7 @@ static int swPipeBase_read(swPipe *p, void *data, int length) return read(object->pipes[0], data, length); } -static int swPipeBase_write(swPipe *p, void *data, int length) +static int swPipeBase_write(swPipe *p, const void *data, int length) { swPipeBase *object = (swPipeBase *) p->object; return write(object->pipes[1], data, length); diff --git a/src/pipe/eventfd.cc b/src/pipe/eventfd.cc index 25d588955e4..bed95bfd317 100644 --- a/src/pipe/eventfd.cc +++ b/src/pipe/eventfd.cc @@ -20,7 +20,7 @@ #include static int swPipeEventfd_read(swPipe *p, void *data, int length); -static int swPipeEventfd_write(swPipe *p, void *data, int length); +static int swPipeEventfd_write(swPipe *p, const void *data, int length); static int swPipeEventfd_close(swPipe *p); typedef struct _swPipeEventfd @@ -114,7 +114,7 @@ static int swPipeEventfd_read(swPipe *p, void *data, int length) return ret; } -static int swPipeEventfd_write(swPipe *p, void *data, int length) +static int swPipeEventfd_write(swPipe *p, const void *data, int length) { int ret; swPipeEventfd *object = (swPipeEventfd *) p->object; diff --git a/src/pipe/unix_socket.cc b/src/pipe/unix_socket.cc index 9e1a9fbd157..759466a2db2 100644 --- a/src/pipe/unix_socket.cc +++ b/src/pipe/unix_socket.cc @@ -17,7 +17,7 @@ #include "swoole.h" static int swPipeUnsock_read(swPipe *p, void *data, int length); -static int swPipeUnsock_write(swPipe *p, void *data, int length); +static int swPipeUnsock_write(swPipe *p, const void *data, int length); static int swPipeUnsock_close(swPipe *p); typedef struct _swPipeUnsock @@ -120,7 +120,7 @@ static int swPipeUnsock_read(swPipe *p, void *data, int length) return read(((swPipeUnsock *) p->object)->socks[0], data, length); } -static int swPipeUnsock_write(swPipe *p, void *data, int length) +static int swPipeUnsock_write(swPipe *p, const void *data, int length) { return write(((swPipeUnsock *) p->object)->socks[1], data, length); } diff --git a/src/protocol/base.cc b/src/protocol/base.cc index 2bce09e012b..6a080e7cb6f 100644 --- a/src/protocol/base.cc +++ b/src/protocol/base.cc @@ -23,7 +23,7 @@ using namespace swoole; /** * return the package total length */ -ssize_t swProtocol_get_package_length(swProtocol *protocol, swSocket *conn, char *data, uint32_t size) +ssize_t swProtocol_get_package_length(swProtocol *protocol, swSocket *conn, const char *data, uint32_t size) { uint16_t length_offset = protocol->package_length_offset; uint8_t package_length_size = protocol->get_package_length_size ? protocol->get_package_length_size(conn) : protocol->package_length_size; diff --git a/src/protocol/http.cc b/src/protocol/http.cc index a22f0e23f72..84001052335 100644 --- a/src/protocol/http.cc +++ b/src/protocol/http.cc @@ -824,7 +824,7 @@ string swHttpRequest_get_date_if_modified_since(swHttpRequest *request) #ifdef SW_USE_HTTP2 -ssize_t swHttpMix_get_package_length(swProtocol *protocol, swSocket *socket, char *data, uint32_t length) +ssize_t swHttpMix_get_package_length(swProtocol *protocol, swSocket *socket, const char *data, uint32_t length) { swConnection *conn = (swConnection *) socket->object; if (conn->websocket_status == WEBSOCKET_STATUS_ACTIVE) @@ -860,7 +860,7 @@ uint8_t swHttpMix_get_package_length_size(swSocket *socket) } } -int swHttpMix_dispatch_frame(swProtocol *proto, swSocket *socket, char *data, uint32_t length) +int swHttpMix_dispatch_frame(swProtocol *proto, swSocket *socket, const char *data, uint32_t length) { swConnection *conn = (swConnection *) socket->object; if (conn->websocket_status == WEBSOCKET_STATUS_ACTIVE) diff --git a/src/protocol/http2.cc b/src/protocol/http2.cc index e6bdc1e15cc..854fd13461a 100644 --- a/src/protocol/http2.cc +++ b/src/protocol/http2.cc @@ -60,7 +60,7 @@ int swHttp2_send_setting_frame(swProtocol *protocol, swSocket *_socket) | Frame Payload (0...) ... +---------------------------------------------------------------+ */ -ssize_t swHttp2_get_frame_length(swProtocol *protocol, swSocket *conn, char *buf, uint32_t length) +ssize_t swHttp2_get_frame_length(swProtocol *protocol, swSocket *conn, const char *buf, uint32_t length) { if (length < SW_HTTP2_FRAME_HEADER_SIZE) { diff --git a/src/protocol/mqtt.cc b/src/protocol/mqtt.cc index 1b97a161b34..445a4114151 100644 --- a/src/protocol/mqtt.cc +++ b/src/protocol/mqtt.cc @@ -23,7 +23,7 @@ void swMqtt_print_package(swMqtt_packet *pkg) printf("type=%d, length=%d\n", pkg->type, pkg->length); } -static sw_inline ssize_t swMqtt_get_length(char *data, uint32_t size, ssize_t *count) +static sw_inline ssize_t swMqtt_get_length(const char *data, uint32_t size, ssize_t *count) { uint8_t byte; int mul = 1; @@ -61,7 +61,7 @@ int swMqtt_unpack(swMqtt_packet *pkg, char *data, uint32_t size) } #endif -ssize_t swMqtt_get_package_length(swProtocol *protocol, swSocket *conn, char *data, uint32_t size) +ssize_t swMqtt_get_package_length(swProtocol *protocol, swSocket *conn, const char *data, uint32_t size) { if (size < SW_MQTT_MIN_LENGTH) { diff --git a/src/protocol/websocket.cc b/src/protocol/websocket.cc index ef32835f295..e6240078a5a 100644 --- a/src/protocol/websocket.cc +++ b/src/protocol/websocket.cc @@ -48,7 +48,7 @@ static inline uint16_t swWebSocket_get_ext_flags(uchar opcode, uchar flags) +---------------------------------------------------------------+ */ -ssize_t swWebSocket_get_package_length(swProtocol *protocol, swSocket *conn, char *buf, uint32_t length) +ssize_t swWebSocket_get_package_length(swProtocol *protocol, swSocket *conn, const char *buf, uint32_t length) { //need more data if (length < SW_WEBSOCKET_HEADER_LEN) @@ -240,13 +240,13 @@ void swWebSocket_print_frame(swWebSocket_frame *frame) } } -int swWebSocket_dispatch_frame(swProtocol *proto, swSocket *_socket, char *data, uint32_t length) +int swWebSocket_dispatch_frame(swProtocol *proto, swSocket *_socket, const char *data, uint32_t length) { swServer *serv = (swServer *) proto->private_data_2; swConnection *conn = (swConnection *) _socket->object; swString frame; bzero(&frame, sizeof(frame)); - frame.str = data; + frame.str = const_cast(data); frame.length = length; swString send_frame = {}; diff --git a/src/server/base.cc b/src/server/base.cc index 9dd51ca4e1c..4e57f552e64 100644 --- a/src/server/base.cc +++ b/src/server/base.cc @@ -77,7 +77,7 @@ static int swFactory_dispatch(swFactory *factory, swSendData *task) pkg.info.flags = SW_EVENT_DATA_PTR; swString_clear(&pkg.data); pkg.data.length = task->info.len; - pkg.data.str = task->data; + pkg.data.str = (char*) task->data; return swWorker_onTask(factory, (swEventData *) &pkg); } diff --git a/src/server/master.cc b/src/server/master.cc index 1e19c7345c9..3f30c21685d 100644 --- a/src/server/master.cc +++ b/src/server/master.cc @@ -1159,7 +1159,7 @@ static int swServer_tcp_send(swServer *serv, int session_id, void *data, uint32_ int swServer_master_send(swServer *serv, swSendData *_send) { uint32_t session_id = _send->info.fd; - char *_send_data = _send->data; + const char *_send_data = _send->data; uint32_t _send_length = _send->info.len; swConnection *conn; diff --git a/src/server/reactor_thread.cc b/src/server/reactor_thread.cc index 99f72ced05a..4a57bac7abb 100644 --- a/src/server/reactor_thread.cc +++ b/src/server/reactor_thread.cc @@ -33,7 +33,7 @@ static int swReactorThread_onRead(swReactor *reactor, swEvent *ev); static int swReactorThread_onWrite(swReactor *reactor, swEvent *ev); static int swReactorThread_onPacketReceived(swReactor *reactor, swEvent *event); static int swReactorThread_onClose(swReactor *reactor, swEvent *event); -static void swReactorThread_onStreamResponse(swStream *stream, char *data, uint32_t length); +static void swReactorThread_onStreamResponse(swStream *stream, const char *data, uint32_t length); static int swReactorThread_is_empty(swReactor *reactor); static void swReactorThread_shutdown(swReactor *reactor); static void swReactorThread_resume_data_receiving(swTimer *timer, swTimer_node *tnode); @@ -106,7 +106,7 @@ static inline enum swReturn_code swReactorThread_verify_ssl_state(swReactor *rea } #endif -static void swReactorThread_onStreamResponse(swStream *stream, char *data, uint32_t length) +static void swReactorThread_onStreamResponse(swStream *stream, const char *data, uint32_t length) { swSendData response; swDataHead *pkg_info = (swDataHead *) data; @@ -524,7 +524,7 @@ static int swReactorThread_onPipeRead(swReactor *reactor, swEvent *ev) return SW_OK; } -int swReactorThread_send2worker(swServer *serv, swWorker *worker, void *data, size_t len) +int swReactorThread_send2worker(swServer *serv, swWorker *worker, const void *data, size_t len) { if (SwooleTG.reactor) { @@ -1187,7 +1187,7 @@ static void swReactorThread_resume_data_receiving(swTimer *timer, swTimer_node * /** * dispatch request data [only data frame] */ -int swReactorThread_dispatch(swProtocol *proto, swSocket *_socket, char *data, uint32_t length) +int swReactorThread_dispatch(swProtocol *proto, swSocket *_socket, const char *data, uint32_t length) { swServer *serv = (swServer *) proto->private_data_2; swSendData task; diff --git a/src/server/worker.cc b/src/server/worker.cc index 5b0561c18ee..23718bd1f81 100644 --- a/src/server/worker.cc +++ b/src/server/worker.cc @@ -25,7 +25,7 @@ static int swWorker_onPipeReceive(swReactor *reactor, swEvent *event); static int swWorker_onStreamAccept(swReactor *reactor, swEvent *event); static int swWorker_onStreamRead(swReactor *reactor, swEvent *event); -static int swWorker_onStreamPackage(swProtocol *proto, swSocket *sock, char *data, uint32_t length); +static int swWorker_onStreamPackage(swProtocol *proto, swSocket *sock, const char *data, uint32_t length); static int swWorker_onStreamClose(swReactor *reactor, swEvent *event); static int swWorker_reactor_is_empty(swReactor *reactor); @@ -206,7 +206,7 @@ static int swWorker_onStreamClose(swReactor *reactor, swEvent *event) return SW_OK; } -static int swWorker_onStreamPackage(swProtocol *proto, swSocket *sock, char *data, uint32_t length) +static int swWorker_onStreamPackage(swProtocol *proto, swSocket *sock, const char *data, uint32_t length) { swServer *serv = (swServer *) proto->private_data_2; @@ -219,7 +219,7 @@ static int swWorker_onStreamPackage(swProtocol *proto, swSocket *sock, char *dat bzero(&task.data, sizeof(task.data)); task.data.length = length - (uint32_t) sizeof(task.info) - 4; - task.data.str = data + 4 + sizeof(task.info); + task.data.str = (char*) (data + 4 + sizeof(task.info)); /** * do task diff --git a/swoole_client.cc b/swoole_client.cc index 1615f1af24a..d68819bc213 100644 --- a/swoole_client.cc +++ b/swoole_client.cc @@ -705,7 +705,7 @@ static void php_swoole_client_free(zval *zobject, swClient *cli) php_swoole_client_set_cli(zobject, NULL); } -ssize_t php_swoole_length_func(swProtocol *protocol, swSocket *_socket, char *data, uint32_t length) +ssize_t php_swoole_length_func(swProtocol *protocol, swSocket *_socket, const char *data, uint32_t length) { zend_fcall_info_cache *fci_cache = (zend_fcall_info_cache *) protocol->private_data; zval zdata; diff --git a/swoole_process_pool.cc b/swoole_process_pool.cc index cfd9b541ac9..8c79f9b1e9a 100644 --- a/swoole_process_pool.cc +++ b/swoole_process_pool.cc @@ -234,7 +234,7 @@ static void pool_onWorkerStart(swProcessPool *pool, int worker_id) } } -static void pool_onMessage(swProcessPool *pool, char *data, uint32_t length) +static void pool_onMessage(swProcessPool *pool, const char *data, uint32_t length) { zval *zobject = (zval *) pool->ptr; process_pool_property *pp = php_swoole_process_pool_get_and_check_pp(zobject); diff --git a/swoole_server_port.cc b/swoole_server_port.cc index 3918b5a3ecd..8859501128c 100644 --- a/swoole_server_port.cc +++ b/swoole_server_port.cc @@ -197,7 +197,7 @@ void php_swoole_server_port_minit(int module_number) /** * [Master-Process] */ -static ssize_t php_swoole_server_length_func(swProtocol *protocol, swSocket *conn, char *data, uint32_t length) +static ssize_t php_swoole_server_length_func(swProtocol *protocol, swSocket *conn, const char *data, uint32_t length) { swServer *serv = (swServer *) protocol->private_data_2; swServer_lock(serv); diff --git a/swoole_socket_coro.cc b/swoole_socket_coro.cc index c9a458e247c..24446f86835 100644 --- a/swoole_socket_coro.cc +++ b/swoole_socket_coro.cc @@ -929,7 +929,7 @@ SW_API bool php_swoole_socket_set_protocol(Socket *sock, zval *zset) sock->protocol.package_length_size = FCGI_HEADER_LEN; sock->protocol.package_length_offset = 0; sock->protocol.package_body_offset = 0; - sock->protocol.get_package_length = [](swProtocol *protocol, swSocket *conn, char *data, uint32_t size) { + sock->protocol.get_package_length = [](swProtocol *protocol, swSocket *conn, const char *data, uint32_t size) { const uint8_t *p = (const uint8_t *) data; ssize_t length = 0; if (size >= FCGI_HEADER_LEN)