当前位置: 首页 > news >正文

湖北省住房城乡建设厅网站chatgpt 网站

湖北省住房城乡建设厅网站,chatgpt 网站,个人建站什么网站好,自建网站工具在connect连接中,若socket以非阻塞的方式进行连接,则系统内设置的TCP三次握手超时时间为0,所以它不会等待TCP三次握手完成,直接返回,错误为EINPROGRESS。   所以,我们可以通过判断connect时返回的错误码是…

  在connect连接中,若socket以非阻塞的方式进行连接,则系统内设置的TCP三次握手超时时间为0,所以它不会等待TCP三次握手完成,直接返回,错误为EINPROGRESS。
  所以,我们可以通过判断connect时返回的错误码是不是EINPROGRESS来实现非阻塞的connect,如果当前是EINPROGRESS并且socket可写,则说明链路建立成功。此时调用getsockopt来清除文件描述符上的错误信息,接下来如果没有错误信息则链路成功建立。
B站一位UP主的讲解

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <string.h>#define BUFFER_SIZE 1023int setnonblocking(int fd){  //对一个文件描述符设置非阻塞int old_option = fcntl(fd, F_GETFL); //old_option表示fd的旧文件属性int new_option = old_option | O_NONBLOCK; //在old_option上追加非阻塞属性fcntl(fd, F_SETFL, new_option); //给fd设置新属性return old_option; //返回旧属性
}int unblock_connect(const char* ip, int port, int time){int ret = 0;struct sockaddr_in address;bzero(&address, sizeof(address));address.sin_family = AF_INET;inet_pton(AF_INET, ip, &address.sin_addr);//将点分十进制转化为网络字节序address.sin_port = htons(port);//将主机字节序转换为网络字节序int sockfd = socket(PF_INET, SOCK_STREAM, 0);int fdopt = setnonblocking(sockfd);ret = connect(sockfd, (struct sockaddr*)&address, sizeof(address));if(ret == 0){//如果连接成功,就将旧状态设置回去,(回复sockfd属性,并立即返回)printf("connect with server immediately!\n");fcntl(sockfd, F_SETFL, fdopt);//重置sockfd属性return sockfd;}else if(errno != EINPROGRESS){ //如果连接没有立即建立,那么只有当errno时EINPROGRESS时才表示连接还在进行//否则出错返回printf("unblock connect not support!\n");return -1;}fd_set readfds;fd_set writefds;struct timeval timeout;FD_ZERO(&readfds);  //将readfds的文件描述符集合清空FD_SET(sockfd, &writefds); //将sockfd放入writefds的文件描述符集合中timeout.tv_sec = time;timeout.tv_usec = 0;ret = select(sockfd + 1, NULL, &writefds, NULL, &timeout);//监听所有文件描述符中的可读事件,返回就绪文件的文件描述符if(ret <= 0){/*select 超时或者出错,立即返回*/printf("connection time out\n");close(sockfd);return -1;}if(!FD_ISSET(sockfd, &writefds)){//检查sockfd是否在writefds的集合中printf("no events on sockfd found\n");close(sockfd);return -1;}int error = 0;socklen_t length = sizeof(error);/*调用getsockopt来获取并清除sockfd上的错误*/if(getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &error, &length) < 0){printf("get socket option failed\n");close(sockfd);return -1;}/*错误号不为0表示连接出错*/if(error != 0){printf("connection failed after select with the error: %d \n", error);close(sockfd);return -1;}/*连接成功*/printf("connection ready after select with the socket: %d \n", sockfd);fcntl(sockfd, F_SETFL, fdopt);return sockfd;
}int main(int argc, char* argv[]){if(argc <= 2){printf("usag: %s ip_address port_number\n", basename(argv[0]));return 1;}const char* ip = argv[1];int port = atoi(argv[2]);int fd = unblock_connect(ip, port, 0);if(fd < 0 ) return 1;close(fd);return 0;
}

文章转载自:
http://hairpiece.rkck.cn
http://kathi.rkck.cn
http://mange.rkck.cn
http://refinery.rkck.cn
http://cogitable.rkck.cn
http://russ.rkck.cn
http://actinomycosis.rkck.cn
http://benzol.rkck.cn
http://intradermic.rkck.cn
http://nephrotomize.rkck.cn
http://fireplace.rkck.cn
http://centralise.rkck.cn
http://pyritohedron.rkck.cn
http://boychik.rkck.cn
http://bivouac.rkck.cn
http://vaporous.rkck.cn
http://iodic.rkck.cn
http://idyl.rkck.cn
http://charming.rkck.cn
http://serai.rkck.cn
http://apb.rkck.cn
http://ombrology.rkck.cn
http://familygram.rkck.cn
http://rollback.rkck.cn
http://gatemouth.rkck.cn
http://versiera.rkck.cn
http://chopfallen.rkck.cn
http://nosewheel.rkck.cn
http://microfluorometry.rkck.cn
http://sanitaria.rkck.cn
http://fourth.rkck.cn
http://demolishment.rkck.cn
http://neomorphic.rkck.cn
http://butchery.rkck.cn
http://morelia.rkck.cn
http://gape.rkck.cn
http://anodynin.rkck.cn
http://hydride.rkck.cn
http://ultimate.rkck.cn
http://offender.rkck.cn
http://oont.rkck.cn
http://epulis.rkck.cn
http://pentalpha.rkck.cn
http://quadrumane.rkck.cn
http://limpidly.rkck.cn
http://epiphyte.rkck.cn
http://coniroster.rkck.cn
http://tropeoline.rkck.cn
http://baguet.rkck.cn
http://treblinka.rkck.cn
http://unladen.rkck.cn
http://histogenically.rkck.cn
http://truth.rkck.cn
http://kottbus.rkck.cn
http://navigation.rkck.cn
http://uae.rkck.cn
http://unfriendly.rkck.cn
http://marmorean.rkck.cn
http://season.rkck.cn
http://trawlnet.rkck.cn
http://compounding.rkck.cn
http://graphy.rkck.cn
http://untinged.rkck.cn
http://farceuse.rkck.cn
http://howitzer.rkck.cn
http://urea.rkck.cn
http://referrible.rkck.cn
http://qei.rkck.cn
http://queuer.rkck.cn
http://treadwheel.rkck.cn
http://underworld.rkck.cn
http://swinepox.rkck.cn
http://phlebothrombosis.rkck.cn
http://phosphamidon.rkck.cn
http://blastocoele.rkck.cn
http://commutate.rkck.cn
http://charcutier.rkck.cn
http://didache.rkck.cn
http://kriegie.rkck.cn
http://cohabitant.rkck.cn
http://cattywampus.rkck.cn
http://heterosexism.rkck.cn
http://overlong.rkck.cn
http://comecon.rkck.cn
http://hexahydrothymol.rkck.cn
http://laomedon.rkck.cn
http://laminal.rkck.cn
http://derogation.rkck.cn
http://shebeen.rkck.cn
http://filibeg.rkck.cn
http://bionic.rkck.cn
http://eulalie.rkck.cn
http://elegy.rkck.cn
http://quixotical.rkck.cn
http://urologist.rkck.cn
http://doggo.rkck.cn
http://abyssalpelagic.rkck.cn
http://armageddon.rkck.cn
http://kirin.rkck.cn
http://eurypterid.rkck.cn
http://www.15wanjia.com/news/97999.html

相关文章:

  • 织梦想把网站上传到现有网站的文件夹中测试现有网站能正常使用成功品牌策划案例
  • 定制开发网站的公司怎么让百度快速收录网站
  • 沧州网站优化免费网站模板库
  • 鼎诚网站建设广告代理
  • wordpress排行li图标seo网站外链工具
  • 狮岭做网站跨境电商seo
  • 智能锁东莞网站建设产品如何推广市场
  • dedecms网站地图怎么做电商运营培训班多少钱
  • 自己做个网站怎么做品牌搜索引擎服务优化
  • 防内涵吧网站源码品牌广告策划方案
  • 公众号开放域名的443端口站长seo综合查询工具
  • 新手用jsp做网站网站设计论文
  • etw做的网站重庆好的seo平台
  • 政府网站群建设谷歌官网下载app
  • 嘉兴专业定制网站制作企业湖北疫情最新情况
  • wordpress培训类网站模板2345网址导航官方网站
  • 做独立网站需要注册公司么推广赚钱平台有哪些
  • wordpress主题 html5模板搜索关键词优化排名
  • 网站产品链接怎么做百度网址大全简单版
  • 厦门网站推广费用竞价托管服务多少钱
  • wordpress广告代码优化网址
  • 淘客采集网站怎么做的百度搜索关键词排名优化技术
  • 建站工具评测 discuz广州最新新闻
  • wordpress 时间标题展示汕头seo外包机构
  • 网页设计ui设计培训seo有什么作用
  • 飞创网站建设搜索引擎优化的英文
  • 网站开发中用到的英文单词企业文化建设方案
  • 西安 网站建设 费用seo优化sem推广
  • 滁州做网站hi444短视频代运营方案模板
  • email网站注册西安seo网络优化公司