From 9017a1a64e8b13cb189fd845b912d91c19d79a96 Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Mon, 8 Aug 2022 12:14:57 +0800 Subject: [PATCH 01/20] Update comm_proxy.cpp --- .../communication/comm_proxy/comm_proxy.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp b/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp index 84c1c97b8..e564fb438 100644 --- a/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp +++ b/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp @@ -53,6 +53,24 @@ static void comm_wait_broadcast_end(SocketRequest** req_arr, int num); * export function definition ************************************************************************************ */ + +/* +function name: comm_proxy_socket +description: This function creates a socket file descriptor whose protocol family is + domain, protocol type is type, and protocol number is protocol. If the + function call is successful, it will return a file descriptor that identifies + the socket. If it fails, it will return - 1. +arguments: The first argument specifies the protocol family, it's used as domain to + set up network communication. + The second argument is used to set the type of socket communication. + The third argument is used to specify a specific type of a protocol, which + is a type in the second argument types' type. +return value: If the function call is successful, it will return a file descriptor that + identifies the socket. If it fails, it will return - 1. +note: none +date: 2022/8/8 +contact tel: 18720816902 +*/ int comm_proxy_socket(int domain, int type, int protocol) { SocketRequest req; From cdc8d9748f425542233f37dc1981dba4b78cb090 Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Mon, 8 Aug 2022 13:45:30 +0800 Subject: [PATCH 02/20] Update comm_proxy.cpp --- .../communication/comm_proxy/comm_proxy.cpp | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp b/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp index e564fb438..a110d4b35 100644 --- a/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp +++ b/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp @@ -172,6 +172,15 @@ ssize_t comm_proxy_addr_recv(int sockfd, void *buf, size_t len, int flags) return comm_proxy_recv(sockfd, buf, len, flags); } +/* +function name: comm_proxy_close +description: The function is used to release the resources allocated + to the socket by the system. +arguments: The argument is the socket file descriptor to be closed. +return value: If the call is successful, return 0; otherwise, return - 1 and set errno. +note: none +contact tel: 18720816902 +*/ int comm_proxy_close(int fd) { SocketRequest req; @@ -223,6 +232,17 @@ int comm_proxy_close(int fd) return result.s_ret; } +/* +function name: comm_proxy_shutdown +description: The function is used to release the resources allocated + to the socket by the system. +arguments: The first argument is a descriptor used to identify a socket. + The second argument is used to describe which operations + are prohibited, which determines the behavior of the function. +return value: If the call is successful, return 0; otherwise, return - 1 and set errno. +note: none +contact tel: 18720816902 +*/ int comm_proxy_shutdown(int fd, int how) { SocketRequest req; @@ -277,6 +297,20 @@ int comm_proxy_shutdown(int fd, int how) return result.s_ret; } +/* +function name: comm_proxy_accept +description: This function extracts the first connection from the waiting connection queue of S, creates + a new socket interface similar to s and returns a handle. +arguments: The first argument is a socket descriptor, which listens for connection after comm_proxy_listen(). + The second argument is a optional pointer pointing to a buffer where the address of the + connection entity known to the communication layer is received. The actual format of the + addr argument is determined by the address family generated when the socket is created. + The third argument is a optional pointer, used together with addr, pointing to the integer + number with the length of addr address. +return value: The return value is a new socket descriptor, which represents a new connection with the client. +note: none +contact tel: 18720816902 +*/ int comm_proxy_accept(int sockfd, struct sockaddr* addr, socklen_t* addrlen) { SocketRequest req; @@ -361,6 +395,16 @@ int comm_proxy_accept4(int sockfd, struct sockaddr* addr, socklen_t* addrlen, in return comm_proxy_accept(sockfd, addr, addrlen); } +/* +function name: comm_proxy_connect +description: This function is used to establish a connection with a specified socket. +arguments: The first argument is used to identify an unconnected socket. + The second argument is a pointer to the sockaddr structure to socket will be connected. + The third argument is byte length of sockaddr structure. +return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. +note: none +contact tel: 18720816902 +*/ int comm_proxy_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { SocketRequest req; @@ -412,6 +456,16 @@ int comm_proxy_connect(int sockfd, const struct sockaddr *addr, socklen_t addrle return result.s_ret; } +/* +function name: comm_proxy_bind +description: This function binds a local address with a set of interfaces. +arguments: The first argument indicates the socket descriptor that has been established. + The second argument is a pointer to the sockaddr structure to socket. + The third argument is byte length of sockaddr structure. +return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. +note: none +contact tel: 18720816902 +*/ int comm_proxy_bind(int sockfd, const struct sockaddr* ServerAddr, socklen_t addrlen) { SocketRequest req; @@ -439,6 +493,15 @@ int comm_proxy_bind(int sockfd, const struct sockaddr* ServerAddr, socklen_t add return result.s_ret; } +/* +function name: comm_proxy_listen +description: This function creates a socket interface and listens for the requested connection. +arguments: The first argument is a descriptor used to identify a bundled but unconnected socket. + The second argument indicates the maximum length of waiting for connection queue +return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. +note: none +contact tel: 18720816902 +*/ int comm_proxy_listen(int sockfd, int backlog) { SocketRequest req; From 32cdbbabff1f6330731a07a55f1d2c568dcc9547 Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Mon, 8 Aug 2022 13:48:22 +0800 Subject: [PATCH 03/20] Update comm_proxy.cpp --- src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp b/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp index a110d4b35..9054f0f79 100644 --- a/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp +++ b/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp @@ -179,6 +179,7 @@ description: The function is used to release the resources allocated arguments: The argument is the socket file descriptor to be closed. return value: If the call is successful, return 0; otherwise, return - 1 and set errno. note: none +date: 2022/8/8 contact tel: 18720816902 */ int comm_proxy_close(int fd) @@ -241,6 +242,7 @@ arguments: The first argument is a descriptor used to identify a socket. are prohibited, which determines the behavior of the function. return value: If the call is successful, return 0; otherwise, return - 1 and set errno. note: none +date: 2022/8/8 contact tel: 18720816902 */ int comm_proxy_shutdown(int fd, int how) @@ -309,6 +311,7 @@ arguments: The first argument is a socket descriptor, which listens for connecti number with the length of addr address. return value: The return value is a new socket descriptor, which represents a new connection with the client. note: none +date: 2022/8/8 contact tel: 18720816902 */ int comm_proxy_accept(int sockfd, struct sockaddr* addr, socklen_t* addrlen) @@ -403,6 +406,7 @@ arguments: The first argument is used to identify an unconnected socket. The third argument is byte length of sockaddr structure. return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. note: none +date: 2022/8/8 contact tel: 18720816902 */ int comm_proxy_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) @@ -464,6 +468,7 @@ arguments: The first argument indicates the socket descriptor that has been esta The third argument is byte length of sockaddr structure. return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. note: none +date: 2022/8/8 contact tel: 18720816902 */ int comm_proxy_bind(int sockfd, const struct sockaddr* ServerAddr, socklen_t addrlen) @@ -500,6 +505,7 @@ arguments: The first argument is a descriptor used to identify a bundled but unc The second argument indicates the maximum length of waiting for connection queue return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. note: none +date: 2022/8/8 contact tel: 18720816902 */ int comm_proxy_listen(int sockfd, int backlog) From a4e1b350cb2a057cc4290256fcc5f4804dbf8e3c Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Mon, 8 Aug 2022 17:38:07 +0800 Subject: [PATCH 04/20] Update comm_proxy.cpp --- .../communication/comm_proxy/comm_proxy.cpp | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp b/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp index 9054f0f79..15d916ce3 100644 --- a/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp +++ b/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp @@ -534,6 +534,19 @@ int comm_proxy_listen(int sockfd, int backlog) return result.s_ret; } +/* +function name: comm_proxy_setsockopt +description: The function is used to set option values for sockets of any type and any state. +arguments: The first argument is a descriptor that identifies a socket interface. + The second argument indicates the level defined by the option. + The third argument specifies the option to be set. + The fourth argument is a pointer to the buffer where the new value of the option to be set is stored. + The fifth argument indicates optval buffer length. +return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. +note: none +date: 2022/8/8 +contact tel: 18720816902 +*/ int comm_proxy_setsockopt(int sockfd, int level, int optname, const void* optval, socklen_t optlen) { SocketRequest req; @@ -563,6 +576,19 @@ int comm_proxy_setsockopt(int sockfd, int level, int optname, const void* optval return result.s_ret; } +/* +function name: comm_proxy_getsockopt +description: The function is used to obtain the current value of the option of any type and any state socket, and store the result in optval. +arguments: The first argument is a descriptor that identifies a socket interface. + The second argument indicates the level defined by the option. + The third argument specifies the socket options to be obtained. + The fourth argument is a pointer to the buffer where the obtained option value is stored. + The fifth argument is a pointer to the length value of optval buffer. +return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. +note: none +date: 2022/8/8 +contact tel: 18720816902 +*/ int comm_proxy_getsockopt(int sockfd, int level, int optname, void* optval, socklen_t* optlen) { SocketRequest req; @@ -591,6 +617,18 @@ int comm_proxy_getsockopt(int sockfd, int level, int optname, void* optval, sock return result.s_ret; } +/* +function name: comm_proxy_getsockname +description: The function is used to get the name of a socket. It is used for a bundled or + connected socket, and the local address will be returned. +arguments: The first argument is a descriptor that identifies a socket interface. + The second argument indicates the address of the receiving socket. + The third argument specifies the length of the name buffer. +return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. +note: none +date: 2022/8/8 +contact tel: 18720816902 +*/ int comm_proxy_getsockname(int sockfd, struct sockaddr* addr, socklen_t* addrlen) { SocketRequest req; @@ -617,6 +655,17 @@ int comm_proxy_getsockname(int sockfd, struct sockaddr* addr, socklen_t* addrlen return result.s_ret; } +/* +function name: comm_proxy_getpeername +description: The function is used to obtain the foreign protocol address associated with a socket. +arguments: The first argument is a descriptor that identifies a socket interface. + The second argument indicates the name structure of the receiver address. + The third argument specifies the length of the name structure. +return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. +note: none +date: 2022/8/8 +contact tel: 18720816902 +*/ int comm_proxy_getpeername(int sockfd, struct sockaddr* addr, socklen_t* addrlen) { SocketRequest req; @@ -643,6 +692,19 @@ int comm_proxy_getpeername(int sockfd, struct sockaddr* addr, socklen_t* addrlen return result.s_ret; } +/* +function name: comm_proxy_fcntl +description: The function can change the nature of the opened file, it provides control over descriptors. + The argument sockfd is a descriptor operated by the argument cmd. For the value of cmd, + fcntl can accept the third argument arg, which is a variable argument. +arguments: The first argument is a descriptor that identifies a socket interface. + The second argument represents the instruction to be operated. + The third argument is a variable argument +return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. +note: none +date: 2022/8/8 +contact tel: 18720816902 +*/ int comm_proxy_fcntl(int sockfd, int cmd, ...) { SocketRequest req; @@ -709,6 +771,17 @@ int comm_proxy_fcntl(int sockfd, int cmd, ...) return result.s_ret; } +/* +function name: comm_proxy_poll +description: The function is used to hang the current file pointer to the waiting queue. +arguments: The first argument is an array of struct pollfd structure type, used to store the socket descriptor whose state needs to be detected. + The second argument is used to mark the total number of structural elements in the array fdarray; + The third argument is the blocking time of the comm_proxy_poll function call. +return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. +note: none +date: 2022/8/8 +contact tel: 18720816902 +*/ int comm_proxy_poll(struct pollfd* fdarray, unsigned long nfds, int timeout) { CommWaitPollParam param; @@ -745,6 +818,15 @@ int comm_proxy_poll(struct pollfd* fdarray, unsigned long nfds, int timeout) return param.s_ret; } +/* +function name: comm_proxy_epoll_create +description: The function is used to create a handle to epoll. +arguments: The only argument size is used to tell the kernel how many listeners there are. +return value: Returns a file descriptor that points to the newly created epoll instance +note: none +date: 2022/8/8 +contact tel: 18720816902 +*/ int comm_proxy_epoll_create(int size) { /* @@ -774,6 +856,21 @@ int comm_proxy_epoll_create1(int flag) return comm_proxy_epoll_create(1); } +/* +function name: comm_proxy_epoll_ctl +description: This system call performs control operations on the epoll instance referenced + by the file descriptor epfd. It requires the operation op to execute the target + file descriptor fd. It's used as epoll's event registration function, it adds, + modifies, or deletes events of interest to the epoll object. +arguments: The first argument is a specific file descriptor for epoll generated by epoll_ create. + The second argument indicates the actions to be taken, such as registering events. + The third argument is associated file descriptor. + The fourth argument is a pointer of type struct epoll_event. +return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. +note: none +date: 2022/8/8 +contact tel: 18720816902 +*/ int comm_proxy_epoll_ctl(int epfd, int op, int fd, struct epoll_event* event) { SocketRequest req; From 8cd2925f93aa112e8b678bf9d16949073a334b97 Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Mon, 8 Aug 2022 17:57:55 +0800 Subject: [PATCH 05/20] Update comm_proxy.cpp --- .../communication/comm_proxy/comm_proxy.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp b/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp index 15d916ce3..fcee84d5c 100644 --- a/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp +++ b/src/gausskernel/cbb/communication/comm_proxy/comm_proxy.cpp @@ -865,7 +865,7 @@ description: This system call performs control operations on the epoll instance arguments: The first argument is a specific file descriptor for epoll generated by epoll_ create. The second argument indicates the actions to be taken, such as registering events. The third argument is associated file descriptor. - The fourth argument is a pointer of type struct epoll_event. + The fourth argument is a pointer of type struct epoll_event, used to tell the kernel what events and actions to listen for. return value: The return value is 0 if succeed, - 1 is returned for failure and error reason is stored in errno. note: none date: 2022/8/8 @@ -1110,6 +1110,23 @@ int comm_proxy_epoll_ctl(int epfd, int op, int fd, struct epoll_event* event) return result.s_ret; } +/* +function name: comm_proxy_epoll_wait +description: Wait for IO events on the specified epoll file descriptor. +arguments: The first argument is a specific file descriptor for epoll generated by epoll_ create. + The second argument is a pointer to type epoll_ event structure, but it is now used + as a container to get the collection of events from the kernel. + The third argument is used to tell how large the container is (number of event + array members), that is, the number of events that can be processed each time. + The fourth argument is the timeout value for waiting for IO events. +return value: When successful, comm_proxy_epoll_wait() returns the number of file descriptors + ready for the requested IO. Returns zero if no file descriptor is ready within the + requested timeout milliseconds. When an error occurs, comm_proxy_epoll_wait() + returns - 1 and sets errno correctly. +note: none +date: 2022/8/8 +contact tel: 18720816902 +*/ int comm_proxy_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) { CommWaitEpollWaitParam param; From 78d7d8e54f48a7c93ca0cccfe29b80e8e771e566 Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Tue, 9 Aug 2022 17:11:49 +0800 Subject: [PATCH 06/20] Update mc_tcp.cpp --- .../cbb/communication/libcomm_core/mc_tcp.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp index d9dfb9555..dc20f0f8a 100644 --- a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp +++ b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp @@ -81,6 +81,27 @@ void mc_tcp_set_keepalive(int fd) mc_tcp_setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, (char*)&count, sizeof(count)); } +/* +function name: mc_tcp_get_peer_name +description: This function is used to obtain the host IP and port number of the host bound to the specific socket. +arguments: The first argument is a descriptor to a specified socket. + The second argument is used to store the host IP address bound to the socket determined by the first parameter, in dotted decimal. + The third parameter is used to store the port number bound to a specific socket, in the order of host bytes. +return value: Return 0 if the function runs successfully. + When the call to the getpeername() function fails: + 1、Return EBADF if the socket argument is not a valid file descriptor. + 2、Return EINVAL if the socket has been shut down. + 3、Return ENOTCONN if the socket is not connected or otherwise has not had the peer pre-specified. + 4、Return ENOTSOCK if the socket argument does not refer to a socket. + 5、Return EOPNOTSUPP if the operation is not supported for the socket protocol. + 6、Return ENOBUFS if insufficient resources were available in the system to complete the call. + Return -2 when the host IP address belongs to IPv4 type, it fails to convert it to dotted decimal. + Return -3 when the host IP address belongs to IPv6 type, it fails to convert it to dotted decimal. + Return -4 when the error type is not any of the above. +note: Allocate a certain amount of memory space for the host and port pointers respectively in advance. +date: 2022/8/9 +contact tel: 18720816902 +*/ int mc_tcp_get_peer_name(int fd, char* host, int* port) { struct sockaddr peeraddr = {0}; From 7679dfe93b0c55db808f6d12813be0262d94ab1d Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Tue, 9 Aug 2022 18:10:13 +0800 Subject: [PATCH 07/20] Update asan_report.pl --- Tools/memory_check/asan_report.pl | 1 - 1 file changed, 1 deletion(-) diff --git a/Tools/memory_check/asan_report.pl b/Tools/memory_check/asan_report.pl index a1870a4c6..f85bf9abd 100644 --- a/Tools/memory_check/asan_report.pl +++ b/Tools/memory_check/asan_report.pl @@ -1,5 +1,4 @@ #!/usr/bin/perl -#Again use warnings; use strict; From 3fde3abb915b5f6d2c0a9ccf5b9682763a1d38e9 Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Tue, 9 Aug 2022 18:11:45 +0800 Subject: [PATCH 08/20] Update encrypt.cpp --- src/bin/gs_guc/encrypt.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/bin/gs_guc/encrypt.cpp b/src/bin/gs_guc/encrypt.cpp index 48783362f..c6f8c2161 100644 --- a/src/bin/gs_guc/encrypt.cpp +++ b/src/bin/gs_guc/encrypt.cpp @@ -100,13 +100,6 @@ static int check_key_num(const char* password) return key_len; } -/* -function name: create_child_dir -description: 函数作用 -arguments: A pointer to string that its type is const char -return value: static void -Note:函数中提醒阅读者需要注意的东西 -*/ static void create_child_dir(const char* pathdir) { if (pathdir == NULL) { From cd677d124301693f65be497eda1b2b4301a5eae4 Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Tue, 9 Aug 2022 23:09:46 +0800 Subject: [PATCH 09/20] Update mc_tcp.cpp --- .../cbb/communication/libcomm_core/mc_tcp.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp index dc20f0f8a..429402e29 100644 --- a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp +++ b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp @@ -142,6 +142,17 @@ int mc_tcp_set_cloexec(int fd) return set_socketopt(fd, 1, FD_CLOEXEC); } +/* +function name: mc_tcp_accept +description: This function will block the process by default until a client connection is established and returns a new available socket. +arguments: The first argument is a socket descriptor to a specific socket. + The second argument is a result parameter, which is used to accept a return value that specifies the address of the client. + The third argument is also a result argument, which is used to accept the size of the sockaddr structure. It indicates the number of bytes occupied by the sockaddr structure. +return value: Return a value less than 0 if an error occurred when call the function accept4(), else return the new fd of socket. +note: none +date: 2022/8/9 +contact tel: 18720816902 +*/ int mc_tcp_accept(int fd, struct sockaddr* sa, socklen_t* salenptr) { int new_fd; @@ -168,6 +179,17 @@ again: return (new_fd); } +/* +function name: mc_tcp_bind +description: This function binds the specified socket to a specific IP address and port. +arguments: The first argument indicates the socket descriptor that has been established. + The second argument is a pointer to the sockaddr structure to socket. + The third argument is byte length of sockaddr structure. +return value: Return errno, the return value is 0 if succeed, else one of other error types is returned for failure. +note: none +date: 2022/8/8 +contact tel: 18720816902 +*/ int mc_tcp_bind(int fd, const struct sockaddr* sa, socklen_t salen) { int error = -1; From 4728c88126a530ee8312badc84766a5c9aa932f0 Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Wed, 10 Aug 2022 11:10:09 +0800 Subject: [PATCH 10/20] Update mc_tcp.cpp --- .../cbb/communication/libcomm_core/mc_tcp.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp index 429402e29..ac2ae21c9 100644 --- a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp +++ b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp @@ -187,7 +187,7 @@ arguments: The first argument indicates the socket descriptor that has been esta The third argument is byte length of sockaddr structure. return value: Return errno, the return value is 0 if succeed, else one of other error types is returned for failure. note: none -date: 2022/8/8 +date: 2022/8/9 contact tel: 18720816902 */ int mc_tcp_bind(int fd, const struct sockaddr* sa, socklen_t salen) @@ -349,6 +349,17 @@ int mc_tcp_read_nonblock(int fd, void* data, int size, int flags) return (size_t)nbytes; } +/* +function name: mc_tcp_check_socket +description: This function binds the specified socket to a specific IP address and port. +arguments: The only argument indicates the specific socket that has been established. +return value: Return -1 if when the recv function wait for the protocol to receive data, + the other end of TCP closes the connection or a real error occurred while + reading data. In other cases, 0 is returned. +note: none +date: 2022/8/10 +contact tel: 18720816902 +*/ int mc_tcp_check_socket(int sock) { char temp_buf[IOV_DATA_SIZE] = {0}; From dc65ea0040f792005d2fca35da16a668e884413a Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Wed, 10 Aug 2022 12:53:44 +0800 Subject: [PATCH 11/20] Update mc_tcp.cpp --- .../cbb/communication/libcomm_core/mc_tcp.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp index ac2ae21c9..f0c5b7854 100644 --- a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp +++ b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp @@ -234,6 +234,19 @@ static void mc_tcp_do_listen(int fd, int backlog) } } + /* +function name: mc_tcp_read_block +description: This function receives data from the other end of TCP in a blocking manner. +arguments: The first argument indicates the specific socket that has been established. + The second argument is a pointer to memory area, we use it to store received data. + The third argument is byte length of the memory area pointed to by the data pointer. + The fourth argument specifies additional operations in addition to the read operation. +return value: If there is no error, it returns the byte length of the successfully read data. If an error + occurs, return - 1. +note: When the data is read successfully, the byte length of the data is greater than 0. +date: 2022/8/10 +contact tel: 18720816902 +*/ int mc_tcp_read_block(int fd, void* data, int size, int flags) { #ifdef LIBCOMM_FAULT_INJECTION_ENABLE @@ -304,6 +317,19 @@ int mc_tcp_read_block(int fd, void* data, int size, int flags) return (size_t)nbytes; } +/* +function name: mc_tcp_read_nonblock +description: This function receives data from the other end of TCP in a non blocking manner. +arguments: The first argument indicates the specific socket that has been established. + The second argument is a pointer to memory area, we use it to store received data. + The third argument is byte length of the memory area pointed to by the data pointer. + The fourth argument specifies additional operations in addition to the read operation. +return value: If the error type is one of the errors represented by EAGAIN, EWOULDBLOCK and EINTR, it returns 0; + other error types return - 1; if there is no error, it returns the byte length of the successfully read data. +note: When the data is read successfully, the byte length of the data is greater than 0. +date: 2022/8/10 +contact tel: 18720816902 +*/ int mc_tcp_read_nonblock(int fd, void* data, int size, int flags) { #ifdef LIBCOMM_FAULT_INJECTION_ENABLE From d0a5914e3fe841c76411541c5d16b20efa1051c4 Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Wed, 10 Aug 2022 15:58:22 +0800 Subject: [PATCH 12/20] Update mc_tcp.cpp --- .../cbb/communication/libcomm_core/mc_tcp.cpp | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp index f0c5b7854..42d678d0d 100644 --- a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp +++ b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp @@ -234,7 +234,7 @@ static void mc_tcp_do_listen(int fd, int backlog) } } - /* +/* function name: mc_tcp_read_block description: This function receives data from the other end of TCP in a blocking manner. arguments: The first argument indicates the specific socket that has been established. @@ -448,6 +448,18 @@ int mc_tcp_check_socket(int sock) return 0; } +/* +function name: mc_tcp_write_block +description: This function writes data to the specified socket in blocking mode. +arguments: The first argument indicates the specific socket that has been established. + The second argument is a pointer to memory area, we use it to store data to be sent. + The third argument is byte length of data to be sent. +return value: If there is no error, it returns the byte length of the successfully sent data. If an error + occurs, return - 1. +note: none +date: 2022/8/10 +contact tel: 18720816902 +*/ int mc_tcp_write_block(int fd, const void* data, int size) { #ifdef LIBCOMM_FAULT_INJECTION_ENABLE @@ -506,6 +518,20 @@ int mc_tcp_write_block(int fd, const void* data, int size) return (size_t)nSend; } +/* +function name: mc_tcp_write_noblock +description: This function writes data to the specified socket in non blocking mode. +arguments: The first argument indicates the specific socket that has been established. + The second argument is a pointer to memory area, we use it to store data to be sent. + The third argument is byte length of data to be sent. +return value: If the sending fails but the failure reason is one of the error types represented by EAGAIN、 + EWOULDBLOCK、EINTR 和ENOBUFS, then 0 is returned; if the error type is other, then - 1 + is returned; If the transmission is successful, the byte length of the successfully transmitted + data is returned +note: none +date: 2022/8/10 +contact tel: 18720816902 +*/ int mc_tcp_write_noblock(int fd, const void* data, int size) { #ifdef LIBCOMM_FAULT_INJECTION_ENABLE From 3a2a690ee8a9df77c574634efbd604e0bf4c25f2 Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Wed, 10 Aug 2022 16:25:37 +0800 Subject: [PATCH 13/20] Update mc_tcp.cpp --- .../cbb/communication/libcomm_core/mc_tcp.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp index 42d678d0d..b07a50652 100644 --- a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp +++ b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp @@ -236,7 +236,8 @@ static void mc_tcp_do_listen(int fd, int backlog) /* function name: mc_tcp_read_block -description: This function receives data from the other end of TCP in a blocking manner. +description: This function receives data from the other end of TCP in a blocking manner, the receiving + process will not end until the data of size byte length is successfully received or a real error occurs in the receiving process arguments: The first argument indicates the specific socket that has been established. The second argument is a pointer to memory area, we use it to store received data. The third argument is byte length of the memory area pointed to by the data pointer. @@ -319,7 +320,8 @@ int mc_tcp_read_block(int fd, void* data, int size, int flags) /* function name: mc_tcp_read_nonblock -description: This function receives data from the other end of TCP in a non blocking manner. +description: This function receives data from the other end of TCP in a non blocking manner, + the data receiving process is only performed once. arguments: The first argument indicates the specific socket that has been established. The second argument is a pointer to memory area, we use it to store received data. The third argument is byte length of the memory area pointed to by the data pointer. @@ -450,7 +452,8 @@ int mc_tcp_check_socket(int sock) /* function name: mc_tcp_write_block -description: This function writes data to the specified socket in blocking mode. +description: This function writes data to the specified socket in blocking mode, the sending process + will not end until all the data are successfully sent or a real error occurs during the sending process arguments: The first argument indicates the specific socket that has been established. The second argument is a pointer to memory area, we use it to store data to be sent. The third argument is byte length of data to be sent. @@ -520,7 +523,8 @@ int mc_tcp_write_block(int fd, const void* data, int size) /* function name: mc_tcp_write_noblock -description: This function writes data to the specified socket in non blocking mode. +description: This function writes data to the specified socket in non blocking mode, + the data transmission process is only performed once. arguments: The first argument indicates the specific socket that has been established. The second argument is a pointer to memory area, we use it to store data to be sent. The third argument is byte length of data to be sent. From 272ebd125fba280b0713e9e50fa38d629cb30979 Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Wed, 10 Aug 2022 18:37:51 +0800 Subject: [PATCH 14/20] Update mc_tcp.cpp --- .../cbb/communication/libcomm_core/mc_tcp.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp index b07a50652..80bc94109 100644 --- a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp +++ b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp @@ -629,6 +629,17 @@ int mc_tcp_addr_init(const char* host, int port, struct sockaddr_storage* ss, in return (error == 1) ? 0 : error; } +/* +function name: mc_tcp_connect_nonblock +description: This function is used to create a socket and establish a connection with the port of the specified host + in non blocking mode. +arguments: The first parameter specifies a specific host, and the second parameter specifies a specific port of the host. +return value: If the connection is successfully established, the file descriptor of the socket connected to the port of the + specified host is returned; otherwise, - 1 is returned. +note: none +date: 2022/8/10 +contact tel: 18720816902 +*/ int mc_tcp_connect_nonblock(const char* host, int port) { int sockfd, n; From 11e6760776b1cbc81134d1d6e3cc973b5c4c9354 Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Wed, 10 Aug 2022 19:16:31 +0800 Subject: [PATCH 15/20] Update mc_tcp.cpp --- .../cbb/communication/libcomm_core/mc_tcp.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp index 80bc94109..fcefcc183 100644 --- a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp +++ b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp @@ -687,6 +687,17 @@ int mc_tcp_connect_nonblock(const char* host, int port) return sockfd; } +/* +function name: mc_tcp_connect +description: This function first obtains the port numbers of other hosts with the same domain name stored through + the ports of specific hosts, and creates a socket to establish a connection with an appropriate one of these ports. +arguments: The first parameter specifies a specific host, and the second parameter specifies a specific port of the host. +return value: The key is to successfully establish a connection with a port in the linked list. If the connection is successful, the + socket file descriptor connected to it will be returned. Otherwise, it will return - 1. +note: none +date: 2022/8/10 +contact tel: 18720816902 +*/ int mc_tcp_connect(const char* host, int port) { #ifdef LIBCOMM_FAULT_INJECTION_ENABLE @@ -777,6 +788,18 @@ retry: return (sockfd); } +/* +function name: mc_tcp_listen +description: This function first obtains the port numbers of other hosts with the same domain name stored through + the ports of specific hosts, and creates a socket to bind with an appropriate one of these ports. +arguments: The first parameter specifies a specific host, and the second parameter specifies a specific port of the host. + The third is used to store size of protocol address. +return value: The key lies in the successful binding with a port in the linked list. If the binding is successful, the socket file + descriptor connected to it will be returned. Otherwise, it will return - 1. +note: none +date: 2022/8/10 +contact tel: 18720816902 +*/ int mc_tcp_listen(const char* host, int port, socklen_t* addrlenp) { #ifdef LIBCOMM_FAULT_INJECTION_ENABLE From f9b4d9a702465cefe354c355e433df79b1c9d5ad Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Wed, 10 Aug 2022 19:19:24 +0800 Subject: [PATCH 16/20] Update mc_tcp.cpp --- .../cbb/communication/libcomm_core/mc_tcp.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp index fcefcc183..f4d8e3a65 100644 --- a/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp +++ b/src/gausskernel/cbb/communication/libcomm_core/mc_tcp.cpp @@ -689,12 +689,13 @@ int mc_tcp_connect_nonblock(const char* host, int port) /* function name: mc_tcp_connect -description: This function first obtains the port numbers of other hosts with the same domain name stored through - the ports of specific hosts, and creates a socket to establish a connection with an appropriate one of these ports. +description: This function first obtains the ports of other hosts with the same domain name stored through + the ports of specific hosts, and creates a socket to establish a connection with an appropriate + one of these ports. arguments: The first parameter specifies a specific host, and the second parameter specifies a specific port of the host. return value: The key is to successfully establish a connection with a port in the linked list. If the connection is successful, the socket file descriptor connected to it will be returned. Otherwise, it will return - 1. -note: none +note: We finally get the infomation of the ports of other hosts through a linked list. date: 2022/8/10 contact tel: 18720816902 */ @@ -790,13 +791,13 @@ retry: /* function name: mc_tcp_listen -description: This function first obtains the port numbers of other hosts with the same domain name stored through +description: This function first obtains the ports of other hosts with the same domain name stored through the ports of specific hosts, and creates a socket to bind with an appropriate one of these ports. arguments: The first parameter specifies a specific host, and the second parameter specifies a specific port of the host. The third is used to store size of protocol address. return value: The key lies in the successful binding with a port in the linked list. If the binding is successful, the socket file descriptor connected to it will be returned. Otherwise, it will return - 1. -note: none +note: We finally get the infomation of the ports of other hosts through a linked list. date: 2022/8/10 contact tel: 18720816902 */ From 95fafe1ce0ea87e9fcabad52733bd26b9203dfd6 Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Thu, 11 Aug 2022 18:33:56 +0800 Subject: [PATCH 18/20] Update libcomm_adapter.cpp --- .../communication/libcomm_utils/libcomm_adapter.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/gausskernel/cbb/communication/libcomm_utils/libcomm_adapter.cpp b/src/gausskernel/cbb/communication/libcomm_utils/libcomm_adapter.cpp index 034326d6c..d0d681a09 100644 --- a/src/gausskernel/cbb/communication/libcomm_utils/libcomm_adapter.cpp +++ b/src/gausskernel/cbb/communication/libcomm_utils/libcomm_adapter.cpp @@ -322,6 +322,19 @@ static int libcomm_tcp_send(LibcommSendInfo* send_info) return send_bytes; } +/* +function name: libcomm_tcp_recv_noidx +description: This function is used to store the message transmitted from the sender, specifically to obtain + the message from a specific socket. +arguments: recv_ info is a pointer of LibcommRecvInfo* type, pointing to the memory to store the data + received. +return value: If it fails to allocate memory for iov_ Item, return RECV_MEM_ERROR; + If it fails to obtain data, no matter it is a message header or a message body, from the specified socket in blocking mode, return RECV_NET_ERROR; + If the function runs successfully, the byte length of the read message body is returned. +note: none +date: 2022/8/11 +contact tel: 18720816902 +*/ static int libcomm_tcp_recv_noidx(LibcommRecvInfo* recv_info) { int sock = recv_info->socket; From 8f463f2f77bd1242feec3d50f6a5303058d4b24a Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Thu, 11 Aug 2022 18:49:14 +0800 Subject: [PATCH 19/20] Update libcomm_adapter.cpp --- .../libcomm_utils/libcomm_adapter.cpp | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/gausskernel/cbb/communication/libcomm_utils/libcomm_adapter.cpp b/src/gausskernel/cbb/communication/libcomm_utils/libcomm_adapter.cpp index d0d681a09..baa37d2b5 100644 --- a/src/gausskernel/cbb/communication/libcomm_utils/libcomm_adapter.cpp +++ b/src/gausskernel/cbb/communication/libcomm_utils/libcomm_adapter.cpp @@ -232,6 +232,21 @@ static int gs_tcp_write_noblock(int node_idx, int sock, const char* msg, int msg return send_bytes; } + +/* +function name: libcomm_tcp_send +description: This function is used to send the message including message head and message body, to + a specific socket. +arguments: send_ info is a pointer of LibcommRecvInfo* type, pointing to the memory storing the data + waiting to be sent. +return value: Data will be sent twice in total. Before sending data, if it is found that the socket to receive + data is not matched with the specified socket, then - 1 will be returned; If the sending of + message head or message body fails, return - 1; If the function runs successfully, the byte + length of the message body sent successfully is returned. +note: none +date: 2022/8/11 +contact tel: 18720816902 +*/ static int libcomm_tcp_send(LibcommSendInfo* send_info) { int sock = send_info->socket; @@ -384,6 +399,23 @@ static int libcomm_tcp_recv_noidx(LibcommRecvInfo* recv_info) return error; } +/* +function name: libcomm_tcp_recv +description: This function is used to store the message transmitted from the sender, specifically to obtain + the message from a specific socket. +arguments: recv_ info is a pointer of LibcommRecvInfo* type, pointing to the memory to store the data + received. +return value: If the receiver has not been determined, call libcomm_tcp_recv_noidx() and take the return value + of (libcomm_tcp_recv_noidx (recv_info)); Return RECV_NET_ERROR if there is an error in the + process of reading the message heade or message body; If there is no data readable in the + receiving buffer of the specified socket at this time or the number of bytes of the data that + has been read is not enough, it returns RECV_NEED_RETRY; If iov_item is NULL, it returns + RECV_MEM_ERROR if it fails to allocate space for it; If the function runs successfully, then + the byte length of the read message head and message body is returned. +note: none +date: 2022/8/11 +contact tel: 18720816902 +*/ int libcomm_tcp_recv(LibcommRecvInfo* recv_info) { MsgHead* msg_head = NULL; From 22b3c75a3639c8d572a83941f8f9e7d204cf202a Mon Sep 17 00:00:00 2001 From: Eao3piq4e Date: Fri, 12 Aug 2022 09:43:45 +0800 Subject: [PATCH 20/20] Update libcomm_client_ssl.cpp --- .../communication/libcomm_utils/libcomm_client_ssl.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/gausskernel/cbb/communication/libcomm_utils/libcomm_client_ssl.cpp b/src/gausskernel/cbb/communication/libcomm_utils/libcomm_client_ssl.cpp index 3676939e8..085f3ef12 100644 --- a/src/gausskernel/cbb/communication/libcomm_utils/libcomm_client_ssl.cpp +++ b/src/gausskernel/cbb/communication/libcomm_utils/libcomm_client_ssl.cpp @@ -137,6 +137,16 @@ static int LibCommClientSSLDHVerifyCb(const SSL* s, const SSL_CTX* ctx, return 1; } +/* +function name: ssl_cipher_list2string +description: This function converts the two-dimensional character array storing the key into a one-dimensional character array. +arguments: The first argument represents the two-dimensional character array to be converted. + The second argument indicates the number of one-dimensional arrays contained in this two-dimensional array. +return value: Returns a pointer to the one-dimensional character array that has been successfully converted. If the conversion fails, NULL is returned. +note: none +date: 2022/8/12 +contact tel: 18720816902 +*/ static char* ssl_cipher_list2string(const char* ciphers[], const int num) { int i; int catlen = 0;