Linux-TCP并发模型相关函数接口-014

2024-03-11 21:44

本文主要是介绍Linux-TCP并发模型相关函数接口-014,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1【TCP】多线程模型

相关函数接口已在前面章节介绍,这里不再赘述

源码示例(1):

//【client.c】
int CreateTcpClient(char *pip, int port)
{int ret = 0;int sockfd = 0;struct sockaddr_in seraddr;sockfd = socket(AF_INET, SOCK_STREAM, 0);if (-1 == sockfd){perror("fail to socket");return -1;}seraddr.sin_family = AF_INET;seraddr.sin_port = htons(port);seraddr.sin_addr.s_addr = inet_addr(pip);ret = connect(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));if (-1 == ret){perror("fail to connect");return -1;}return sockfd;
}int main(void)
{int sockfd = 0;char tmpbuff[4096] = {"hello world"};int cnt = 0;ssize_t nsize = 0;sockfd = CreateTcpClient("192.168.1.183", 50000);while (1){memset(tmpbuff, 0, sizeof(tmpbuff));sprintf(tmpbuff, "hello world --- %d", cnt);cnt++;nsize = send(sockfd, tmpbuff, strlen(tmpbuff), 0);if (-1 == nsize){perror("fail to send");return -1;}memset(tmpbuff, 0, sizeof(tmpbuff));nsize = recv(sockfd, tmpbuff, sizeof(tmpbuff), 0);if (-1 == nsize){perror("fail to recv");return -1;}printf("RECV:%s\n", tmpbuff);}close(sockfd);return 0;
}//【server.c】
int CreateListenSocket(char *pip, int port)
{int ret = 0;int sockfd = 0;struct sockaddr_in seraddr;sockfd = socket(AF_INET, SOCK_STREAM, 0);if (-1 == sockfd){perror("fail to socket");return -1;}seraddr.sin_family = AF_INET;seraddr.sin_port = htons(port);seraddr.sin_addr.s_addr = inet_addr(pip);ret = bind(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));if (-1 == ret){perror("fail to bind");return -1;}ret = listen(sockfd, 10);if (-1 == ret){perror("fail to listen");return -1;}return sockfd;
}void *HandleTcpClient(void *arg)
{char tmpbuff[4096] = {0};ssize_t nsize = 0;int confd = arg;while (1){memset(tmpbuff, 0, sizeof(tmpbuff));nsize = recv(confd, tmpbuff, sizeof(tmpbuff), 0);if (-1 == nsize){perror("fail to recv");return NULL;}else if (0 == nsize){return NULL;}sprintf(tmpbuff, "%s ----echo", tmpbuff);nsize = send(confd, tmpbuff, strlen(tmpbuff), 0);if (-1 == nsize){perror("fail to send");return NULL;}}return NULL;
}int main(void)
{int sockfd = 0;int confd = 0;pthread_t tid;pthread_attr_t attr;sockfd = CreateListenSocket("192.168.1.183", 50000);pthread_attr_init(&attr);pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);while (1){confd = accept(sockfd, NULL, NULL);if (-1 == confd){perror("fail to accept");return -1;}pthread_create(&tid, &attr, HandleTcpClient, confd);}close(sockfd);return 0;
}

2【IO】模型

2.1阻塞IO

相关函数接口已在前面章节介绍,这里不再赘述

2.2非阻塞IO

源码示例(1):

//【write.c】
int main(void)
{int fd = 0;char tmpbuff[4096] = {0};mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_WRONLY);if (-1 == fd){perror("fail to open");return -1;}while (1){gets(tmpbuff);write(fd, tmpbuff, strlen(tmpbuff));}close(fd);return 0;
}//【read.c】
int main(void)
{int fd = 0;int flags = 0;char *pret = NULL;ssize_t nsize = 0;char tmpbuff[4096] = {0};mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_RDONLY);if (-1 == fd){perror("fail to open");return -1;}flags = fcntl(fd, F_GETFL);flags |= O_NONBLOCK;fcntl(fd, F_SETFL, flags);flags = fcntl(0, F_GETFL);flags |= O_NONBLOCK;fcntl(0, F_SETFL, flags);while (1){memset(tmpbuff, 0, sizeof(tmpbuff));pret = gets(tmpbuff);if (pret != NULL){printf("STDIN:%s\n", tmpbuff);}memset(tmpbuff, 0, sizeof(tmpbuff));nsize = read(fd, tmpbuff, sizeof(tmpbuff));if (nsize > 0){printf("FIFO:%s\n", tmpbuff);}}close(fd);return 0;
}

2.3异步IO

源码示例(1):

//【write.c】
int main(void)
{int fd = 0;char tmpbuff[4096] = {0};mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_WRONLY);if (-1 == fd){perror("fail to open");return -1;}while (1){gets(tmpbuff);write(fd, tmpbuff, strlen(tmpbuff));}close(fd);return 0;
}//【read.c】
int fd = 0;void handler(int signo)
{char tmpbuff[4096] = {0};ssize_t nsize = 0;memset(tmpbuff, 0, sizeof(tmpbuff));nsize = read(fd, tmpbuff, sizeof(tmpbuff));if (nsize > 0){printf("FIFO:%s\n", tmpbuff);}return;
}int main(void)
{int flags = 0;char *pret = NULL;ssize_t nsize = 0;char tmpbuff[4096] = {0};signal(SIGIO, handler);mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_RDONLY);if (-1 == fd){perror("fail to open");return -1;}flags = fcntl(fd, F_GETFL);flags |= O_ASYNC;fcntl(fd, F_SETFL, flags);fcntl(fd, F_SETOWN, getpid());while (1){memset(tmpbuff, 0, sizeof(tmpbuff));gets(tmpbuff);printf("STDIN:%s\n", tmpbuff);}close(fd);
}

2.4多路复用IO

2.4.1【select】

2.4.1.1函数原型
【int select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *timeout);】
2.4.1.2函数功能
监听文件描述符集合中是否有文件描述编程ready状态
2.4.1.3函数参数
1.【nfds】:最大文件描述符的值+1 
2.【readfds】:读文件描述符集合
3.【writefds】:写文件描述符集合
4.【exceptfds】:其余文件描述符集合
5.【timeout】:等待的时长【NULL】:表示一直等待
2.4.1.4返回值
【成功】:返回文件描述符集合中的文件描述符个数
【失败】:返回【-1】
2.4.1.5常用的几个函数

1.【FD_CLR】

(1)函数原型:【void FD_CLR(int fd, fd_set *set);】
(2)函数功能: 将文件描述符fd从集合中清除 
(3)函数参数:【fd】:【set】:

(4)返回值:

2.【FD_ISSET】

(1)函数原型:【int  FD_ISSET(int fd, fd_set *set);】
(2)函数功能: 判断文件描述符fd是否仍在集合中
(3)函数参数:【fd】:【set】:
(4)返回值:

3.【FD_SET】

(1)函数原型:【int  FD_ISSET(int fd, fd_set *set);】
(2)函数功能: 将文件描述符fd加入到集合中
(3)函数参数:【fd】:【set】:
(4)返回值:

4.【FD_ZERO】

(1)函数原型:【int  FD_ISSET(int fd, fd_set *set);】
(2)函数功能: 将文件描述符集合清0
(3)函数参数:
【set】:
(4)返回值:

源码示例(1):

//【write.c】
int main(void)
{int fd = 0;char tmpbuff[4096] = {0};mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_WRONLY);if (-1 == fd){perror("fail to open");return -1;}while (1){gets(tmpbuff);write(fd, tmpbuff, strlen(tmpbuff));}close(fd);return 0;
}//【read.c】
int main(void)
{int fd = 0;int flags = 0;char *pret = NULL;ssize_t nsize = 0;char tmpbuff[4096] = {0};fd_set rdfds;fd_set tmpfds;int ret = 0;mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_RDONLY);if (-1 == fd){perror("fail to open");return -1;}FD_ZERO(&rdfds);FD_SET(fd, &rdfds);FD_SET(0, &rdfds);while (1){tmpfds = rdfds;ret = select(fd+1, &tmpfds, NULL, NULL, NULL);if (-1 == ret){perror("fail to select");return -1;}if (FD_ISSET(fd, &tmpfds)){memset(tmpbuff, 0, sizeof(tmpbuff));read(fd, tmpbuff, sizeof(tmpbuff));printf("FIFO:%s\n", tmpbuff);}if (FD_ISSET(0, &tmpfds)){memset(tmpbuff, 0, sizeof(tmpbuff));gets(tmpbuff);printf("STDIN:%s\n", tmpbuff);}}close(fd);return 0;
}

源码示例(2):

//【client.c】
int CreateTcpClient(char *pip, int port)
{int ret = 0;int sockfd = 0;struct sockaddr_in seraddr;sockfd = socket(AF_INET, SOCK_STREAM, 0);if (-1 == sockfd){perror("fail to socket");return -1;}seraddr.sin_family = AF_INET;seraddr.sin_port = htons(port);seraddr.sin_addr.s_addr = inet_addr(pip);ret = connect(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));if (-1 == ret){perror("fail to connect");return -1;}return sockfd;
}int main(void)
{int sockfd = 0;char tmpbuff[4096] = {"hello world"};int cnt = 0;ssize_t nsize = 0;sockfd = CreateTcpClient("192.168.1.183", 50000);while (1){memset(tmpbuff, 0, sizeof(tmpbuff));sprintf(tmpbuff, "hello world --- %d", cnt);cnt++;nsize = send(sockfd, tmpbuff, strlen(tmpbuff), 0);if (-1 == nsize){perror("fail to send");return -1;}memset(tmpbuff, 0, sizeof(tmpbuff));nsize = recv(sockfd, tmpbuff, sizeof(tmpbuff), 0);if (-1 == nsize){perror("fail to recv");return -1;}printf("RECV:%s\n", tmpbuff);}close(sockfd);return 0;
}//【server.c】
int CreateListenSocket(char *pip, int port)
{int ret = 0;int sockfd = 0;struct sockaddr_in seraddr;sockfd = socket(AF_INET, SOCK_STREAM, 0);if (-1 == sockfd){perror("fail to socket");return -1;}seraddr.sin_family = AF_INET;seraddr.sin_port = htons(port);seraddr.sin_addr.s_addr = inet_addr(pip);ret = bind(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));if (-1 == ret){perror("fail to bind");return -1;}ret = listen(sockfd, 10);if (-1 == ret){perror("fail to listen");return -1;}return sockfd;
}int HandleTcpClient(int confd)
{char tmpbuff[4096] = {0};ssize_t nsize = 0;memset(tmpbuff, 0, sizeof(tmpbuff));nsize = recv(confd, tmpbuff, sizeof(tmpbuff), 0);if (-1 == nsize){perror("fail to recv");return -1;}else if (0 == nsize){return 0;}sprintf(tmpbuff, "%s ----echo", tmpbuff);nsize = send(confd, tmpbuff, strlen(tmpbuff), 0);if (-1 == nsize){perror("fail to send");return -1;}return nsize;
}int main(void)
{int sockfd = 0;int confd = 0;fd_set rdfds;fd_set tmpfds;int maxfd = 0;int ret = 0;int i = 0;sockfd = CreateListenSocket("192.168.1.183", 50000);FD_ZERO(&rdfds);FD_SET(sockfd, &rdfds);maxfd = sockfd;while (1){tmpfds = rdfds;ret = select(maxfd+1, &tmpfds, NULL, NULL, NULL);if (-1 == ret){perror("fail to select");return -1;}if (FD_ISSET(sockfd, &tmpfds)){confd = accept(sockfd, NULL, NULL);if (-1 == confd){perror("fail to accept");FD_CLR(sockfd, &rdfds);close(sockfd);continue;}FD_SET(confd, &rdfds);maxfd = maxfd > confd ? maxfd : confd;}for (i = sockfd+1; i <= maxfd; i++){if (FD_ISSET(i, &tmpfds)){ret = HandleTcpClient(i);if (-1 == ret){fprintf(stderr, "handle client failed!\n");FD_CLR(i, &rdfds);close(i);continue;}else if (0 == ret){fprintf(stderr, "client disconnected!\n");FD_CLR(i, &rdfds);close(i);continue;}}}}close(confd);close(sockfd);return 0;
}

2.4.2【poll】

2.4.2.1函数原型
【int poll(struct pollfd *fds, nfds_t nfds, int timeout);】
2.4.2.2函数功能
监听文件描述符集合是否有事件发生
2.4.2.3函数参数
1.【fds】:监听文件描述符集合数组空间首地址
2.【nfds】:监听文件描述符集合元素个数
3.【timeout】:等待的时间【-1】: 一直等待

结构体说明:

struct pollfd {int   fd;/* file descriptor 监听的文件描述符*/short events;/* requested events 要监听的事件*/short revents;/* returned events 实际产生的事件*/
};
//结构体成员介绍
fd:监听的文件描述符
events:要监听的事件  POLLIN:是否可读  POLLOUT:是否可写
revents:实际产生的事件 
2.4.2.4返回值
【成功】:返回产生事件的文件描述符个数
【失败】:返回【-1】

源码示例(1):

//【write.c】
int main(void)
{int fd = 0;char tmpbuff[4096] = {0};mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_WRONLY);if (-1 == fd){perror("fail to open");return -1;}while (1){gets(tmpbuff);write(fd, tmpbuff, strlen(tmpbuff));}close(fd);return 0;
}//【read.c】
int main(void)
{int fd = 0;int flags = 0;char *pret = NULL;ssize_t nsize = 0;char tmpbuff[4096] = {0};struct pollfd fds[2];int nready = 0;mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_RDONLY);if (-1 == fd){perror("fail to open");return -1;}fds[0].fd = fd;fds[0].events = POLLIN;fds[1].fd = 0;fds[1].events = POLLIN;while (1){nready = poll(fds, 2, -1);if (-1 == nready){perror("fail to poll");return -1;}if (fds[0].revents & POLLIN){memset(tmpbuff, 0, sizeof(tmpbuff));read(fd, tmpbuff, sizeof(tmpbuff));printf("FIFO:%s\n", tmpbuff);}if (fds[1].revents & POLLIN){memset(tmpbuff, 0, sizeof(tmpbuff));gets(tmpbuff);printf("STDIN:%s\n", tmpbuff);}}close(fd);
}

源码示例(2):

//【client.c】
int CreateTcpClient(char *pip, int port)
{int ret = 0;int sockfd = 0;struct sockaddr_in seraddr;sockfd = socket(AF_INET, SOCK_STREAM, 0);if (-1 == sockfd){perror("fail to socket");return -1;}seraddr.sin_family = AF_INET;seraddr.sin_port = htons(port);seraddr.sin_addr.s_addr = inet_addr(pip);ret = connect(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));if (-1 == ret){perror("fail to connect");return -1;}return sockfd;
}int main(void)
{int sockfd = 0;char tmpbuff[4096] = {"hello world"};int cnt = 0;ssize_t nsize = 0;sockfd = CreateTcpClient("192.168.1.183", 50000);while (1){memset(tmpbuff, 0, sizeof(tmpbuff));sprintf(tmpbuff, "hello world --- %d", cnt);cnt++;nsize = send(sockfd, tmpbuff, strlen(tmpbuff), 0);if (-1 == nsize){perror("fail to send");return -1;}memset(tmpbuff, 0, sizeof(tmpbuff));nsize = recv(sockfd, tmpbuff, sizeof(tmpbuff), 0);if (-1 == nsize){perror("fail to recv");return -1;}printf("RECV:%s\n", tmpbuff);}close(sockfd);return 0;
}//【server.c】
int CreateListenSocket(char *pip, int port)
{int ret = 0;int sockfd = 0;struct sockaddr_in seraddr;sockfd = socket(AF_INET, SOCK_STREAM, 0);if (-1 == sockfd){perror("fail to socket");return -1;}seraddr.sin_family = AF_INET;seraddr.sin_port = htons(port);seraddr.sin_addr.s_addr = inet_addr(pip);ret = bind(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));if (-1 == ret){perror("fail to bind");return -1;}ret = listen(sockfd, 10);if (-1 == ret){perror("fail to listen");return -1;}return sockfd;
}int HandleTcpClient(int confd)
{char tmpbuff[4096] = {0};ssize_t nsize = 0;memset(tmpbuff, 0, sizeof(tmpbuff));nsize = recv(confd, tmpbuff, sizeof(tmpbuff), 0);if (-1 == nsize){perror("fail to recv");return -1;}else if (0 == nsize){return 0;}sprintf(tmpbuff, "%s ----echo", tmpbuff);nsize = send(confd, tmpbuff, strlen(tmpbuff), 0);if (-1 == nsize){perror("fail to send");return -1;}return nsize;
}int InitFds(struct pollfd *fds, int maxlen)
{int i = 0;for (i = 0; i < maxlen; i++){fds[i].fd = -1;}return 0;
}int AddFd(struct pollfd *fds, int maxlen, int fd, short env)
{int i = 0;for (i = 0; i < maxlen; i++){if (fds[i].fd == -1){fds[i].fd = fd;fds[i].events = env;break;}}if (i == maxlen){return -1;}return 0;
}int DeleteFd(struct pollfd *fds, int maxlen, int fd)
{int i = 0;for (i = 0; i < maxlen; i++){if (fds[i].fd == fd){fds[i].fd = -1;break;}}return 0;
}int main(void)
{int sockfd = 0;int confd = 0;struct pollfd fds[1024];int nready = 0;int i = 0;int ret = 0;sockfd = CreateListenSocket("192.168.1.183", 50000);InitFds(fds, 1024);AddFd(fds, 1024, sockfd, POLLIN);while (1){nready = poll(fds, 1024, -1);if (-1 == nready){perror("fail to poll");return -1;}for (i = 0; i < 1024; i++){if (fds[i].fd == -1){continue;}if (fds[i].revents & POLLIN && fds[i].fd == sockfd){confd = accept(sockfd, NULL, NULL);if (-1 == confd){perror("fail to accept");DeleteFd(fds, 1024, sockfd);close(sockfd);continue;}AddFd(fds, 1024, confd, POLLIN);}else if (fds[i].revents & POLLIN && fds[i].fd != sockfd){ret = HandleTcpClient(fds[i].fd);if (-1 == ret){fprintf(stderr, "handle tcp client failed!\n");close(fds[i].fd);DeleteFd(fds, 1024, fds[i].fd);continue;}else if (0 == ret){fprintf(stderr, "client disconnected!\n");close(fds[i].fd);DeleteFd(fds, 1024, fds[i].fd);continue;}}}}close(sockfd);return 0;
}

2.4.3【epoll】

2.4.3.1函数原型

【int epoll_create(int size);】

2.4.3.2函数功能
创建一张内核事件表
2.4.3.3函数参数
【size】:事件的个数
2.4.3.4返回值
【成功】:返回文件描述符
【失败】:返回【-1】

2.4.4【epoll_ctl】

2.4.4.1函数原型

【int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);】

2.4.4.2函数功能

维护epoll时间表

2.4.4.3函数参数
1.【epfd】:事件表的文件描述符
2.【op】:【EPOLL_CTL_ADD】:添加事件【EPOLL_CTL_MOD】:修改事件【EPOLL_CTL_DEL】:删除事件
3.【fd】:操作的文件描述符
4.【event】:事件对应的事件

结构体说明:

typedef union epoll_data {void        *ptr;int          fd;uint32_t     u32;uint64_t     u64;
} epoll_data_t;struct epoll_event {uint32_t     events;      /* Epoll events */epoll_data_t data;        /* User data variable */
};
2.4.4.4返回值
【成功】:返回【0】 
【失败】:返回【-1】

2.4.5【epoll_wait】

2.4.5.1函数原型
【int epoll_wait(int epfd, struct epoll_event *events,int maxevents, int timeout);】
2.4.5.2函数功能
监听事件表中的事件
2.4.5.3函数参数
1.【epfd】:文件描述符
2.【events】:存放实际产生事件的数组空间首地址
3.【maxevents】:最多存放事件的个数
4.【timeout】:设定监听的时间(超过该时间则不再监听)【-1】:一直监听直到有事件发生
2.4.5.4返回值
【成功】:返回产生事件的文件描述符个数
【失败】:返回【-1】
【超时】:如果时间达到仍没有事件发生返回【0】

源码示例(1):

//【write.c】
int main(void)
{int fd = 0;char tmpbuff[4096] = {0};mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_WRONLY);if (-1 == fd){perror("fail to open");return -1;}while (1){gets(tmpbuff);write(fd, tmpbuff, strlen(tmpbuff));}close(fd);return 0;
}//【read.c】
int main(void)
{int fd = 0;int flags = 0;char *pret = NULL;ssize_t nsize = 0;char tmpbuff[4096] = {0};int epfd = 0;struct epoll_event env;struct epoll_event retenv[2];int nready = 0;int i = 0;mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_RDONLY);if (-1 == fd){perror("fail to open");return -1;}epfd = epoll_create(2);if (-1 == epfd){perror("fail to epoll_create");return -1;}env.events = EPOLLIN;env.data.fd = fd;epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &env);env.events = EPOLLIN;env.data.fd = 0;epoll_ctl(epfd, EPOLL_CTL_ADD, 0, &env);while (1){nready = epoll_wait(epfd, retenv, 2, -1);if (-1 == nready){perror("fail to epoll_wait");return -1;}for (i = 0; i < nready; i++){if (retenv[i].data.fd == 0){memset(tmpbuff, 0, sizeof(tmpbuff));gets(tmpbuff);printf("STDIN:%s\n", tmpbuff);}else if (retenv[i].data.fd == fd){memset(tmpbuff, 0, sizeof(tmpbuff));read(fd, tmpbuff, sizeof(tmpbuff));printf("FIFO:%s\n", tmpbuff);}}}close(fd);
}

源码示例(2):

这篇关于Linux-TCP并发模型相关函数接口-014的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/799174

相关文章

Linux换行符的使用方法详解

《Linux换行符的使用方法详解》本文介绍了Linux中常用的换行符LF及其在文件中的表示,展示了如何使用sed命令替换换行符,并列举了与换行符处理相关的Linux命令,通过代码讲解的非常详细,需要的... 目录简介检测文件中的换行符使用 cat -A 查看换行符使用 od -c 检查字符换行符格式转换将

Linux系统配置NAT网络模式的详细步骤(附图文)

《Linux系统配置NAT网络模式的详细步骤(附图文)》本文详细指导如何在VMware环境下配置NAT网络模式,包括设置主机和虚拟机的IP地址、网关,以及针对Linux和Windows系统的具体步骤,... 目录一、配置NAT网络模式二、设置虚拟机交换机网关2.1 打开虚拟机2.2 管理员授权2.3 设置子

Linux系统中卸载与安装JDK的详细教程

《Linux系统中卸载与安装JDK的详细教程》本文详细介绍了如何在Linux系统中通过Xshell和Xftp工具连接与传输文件,然后进行JDK的安装与卸载,安装步骤包括连接Linux、传输JDK安装包... 目录1、卸载1.1 linux删除自带的JDK1.2 Linux上卸载自己安装的JDK2、安装2.1

Kotlin 作用域函数apply、let、run、with、also使用指南

《Kotlin作用域函数apply、let、run、with、also使用指南》在Kotlin开发中,作用域函数(ScopeFunctions)是一组能让代码更简洁、更函数式的高阶函数,本文将... 目录一、引言:为什么需要作用域函数?二、作用域函China编程数详解1. apply:对象配置的 “流式构建器”最

Java并发编程必备之Synchronized关键字深入解析

《Java并发编程必备之Synchronized关键字深入解析》本文我们深入探索了Java中的Synchronized关键字,包括其互斥性和可重入性的特性,文章详细介绍了Synchronized的三种... 目录一、前言二、Synchronized关键字2.1 Synchronized的特性1. 互斥2.

Linux卸载自带jdk并安装新jdk版本的图文教程

《Linux卸载自带jdk并安装新jdk版本的图文教程》在Linux系统中,有时需要卸载预装的OpenJDK并安装特定版本的JDK,例如JDK1.8,所以本文给大家详细介绍了Linux卸载自带jdk并... 目录Ⅰ、卸载自带jdkⅡ、安装新版jdkⅠ、卸载自带jdk1、输入命令查看旧jdkrpm -qa

go中空接口的具体使用

《go中空接口的具体使用》空接口是一种特殊的接口类型,它不包含任何方法,本文主要介绍了go中空接口的具体使用,具有一定的参考价值,感兴趣的可以了解一下... 目录接口-空接口1. 什么是空接口?2. 如何使用空接口?第一,第二,第三,3. 空接口几个要注意的坑坑1:坑2:坑3:接口-空接口1. 什么是空接

Linux samba共享慢的原因及解决方案

《Linuxsamba共享慢的原因及解决方案》:本文主要介绍Linuxsamba共享慢的原因及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux samba共享慢原因及解决问题表现原因解决办法总结Linandroidux samba共享慢原因及解决

Java的IO模型、Netty原理解析

《Java的IO模型、Netty原理解析》Java的I/O是以流的方式进行数据输入输出的,Java的类库涉及很多领域的IO内容:标准的输入输出,文件的操作、网络上的数据传输流、字符串流、对象流等,这篇... 目录1.什么是IO2.同步与异步、阻塞与非阻塞3.三种IO模型BIO(blocking I/O)NI

新特性抢先看! Ubuntu 25.04 Beta 发布:Linux 6.14 内核

《新特性抢先看!Ubuntu25.04Beta发布:Linux6.14内核》Canonical公司近日发布了Ubuntu25.04Beta版,这一版本被赋予了一个活泼的代号——“Plu... Canonical 昨日(3 月 27 日)放出了 Beta 版 Ubuntu 25.04 系统镜像,代号“Pluc