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

石嘴山市建设局网站公司建网站多少钱一个

石嘴山市建设局网站,公司建网站多少钱一个,做殡葬名片的网站,wordpress前台登陆插件read函数的行为 read返回0表示正常结束条件,而非错误,具体场景包括: 文件读取结束,到达文件末尾(EOF)连接关闭:在socket通信中,对端正常关闭连接(如执行close()或进程终…

read函数的行为

read返回0表示正常结束条件,而非错误,具体场景包括:

  1. 文件读取结束,到达文件末尾(EOF)
  2. 连接关闭:在socket通信中,对端正常关闭连接(如执行close()或进程终止)
  3. 管道/流结束:从管道或FIFO读取时写入端已关闭

此时不需要处理错误码,应作为正常逻辑分支处理。

read返回-1时,需通过errno判断具体错误类型

错误码触发场景处理建议
EAGAIN非阻塞模式下无数据可读(与EWOULDBLOCK等价)等待后重试或切换为阻塞模式
EBADF无效文件描述符(如未打开/已关闭的fd)检查fd生命周期管理逻辑
EFAULT缓冲区指针越界(buf指向非法内存地址)检查内存分配和指针有效性
EINTR系统调用被信号中断重启read调用(需实现重试逻辑)
EINVAL文件描述符不支持读取(如O_DIRECT模式参数错误)检查open时的打开模式
EIO底层I/O错误(如磁盘故障、网络硬件错误)检查硬件状态,可能需要终止操作
EISDIR尝试读取目录文件(需通过readdir访问目录)[^系统标准]修改代码逻辑,区分文件和目录访问方式

man 2 read

READ(2)                                                                      Linux Programmer's Manual                                                                      READ(2)NAMEread - read from a file descriptorSYNOPSIS#include <unistd.h>ssize_t read(int fd, void *buf, size_t count);DESCRIPTIONread() attempts to read up to count bytes from file descriptor fd into the buffer starting at buf.On files that support seeking, the read operation commences at the current file offset, and the file offset is incremented by the number of bytes read.  If the current fileoffset is at or past the end of file, no bytes are read, and read() returns zero.If count is zero, read() may detect the errors described below.  In the absence of any errors, or if read() does not check for errors, a read() with a count  of  0  returnszero and has no other effects.If count is greater than SSIZE_MAX, the result is unspecified.RETURN VALUEOn  success,  the  number  of  bytes  read is returned (zero indicates end of file), and the file position is advanced by this number.  It is not an error if this number issmaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, orbecause  we are reading from a pipe, or from a terminal), or because read() was interrupted by a signal.  On error, -1 is returned, and errno is set appropriately.  In thiscase it is left unspecified whether the file position (if any) changes.ERRORSEAGAIN The file descriptor fd refers to a file other than a socket and has been marked nonblocking (O_NONBLOCK), and the read would block.EAGAIN or EWOULDBLOCKThe file descriptor fd refers to a socket and has been marked nonblocking (O_NONBLOCK), and the read would block.  POSIX.1-2001 allows either error  to  be  returnedfor this case, and does not require these constants to have the same value, so a portable application should check for both possibilities.EBADF  fd is not a valid file descriptor or is not open for reading.EFAULT buf is outside your accessible address space.EINTR  The call was interrupted by a signal before any data was read; see signal(7).EINVAL fd is attached to an object which is unsuitable for reading; or the file was opened with the O_DIRECT flag, and either the address specified in buf, the value speci‐fied in count, or the current file offset is not suitably aligned.EINVAL fd was created via a call to timerfd_create(2) and the wrong size buffer was given to read(); see timerfd_create(2) for further information.EIO    I/O error.  This will happen for example when the process is in a background process group, tries to read from its controlling terminal, and either it is ignoring orblocking SIGTTIN or its process group is orphaned.  It may also occur when there is a low-level I/O error while reading from a disk or tape.EISDIR fd refers to a directory.Other  errors  may occur, depending on the object connected to fd.  POSIX allows a read() that is interrupted after reading some data to return -1 (with errno set to EINTR)or to return the number of bytes already read.

read错误码对应int

#include <errno.h>
#include <stdio.h>int main()
{printf("EAGAIN = %d\n", EAGAIN);printf("EBADF = %d\n", EBADF);printf("EFAULT = %d\n", EFAULT);printf("EINTR = %d\n", EINTR);printf("EINVAL = %d\n", EINVAL);printf("EIO = %d\n", EIO);printf("EISDIR = %d\n", EISDIR);return 0;
}

EAGAIN = 11
EBADF = 9
EFAULT = 14
EINTR = 4
EINVAL = 22
EIO = 5
EISDIR = 21

read实例

第一步:服务端执行net

$ ./net 
Waiting for client connection...

第二步:服务端监听8484端口
···
sudo tcpdump -i lo -X ‘port 8484’
···

第三步:本机telnet 127.0.0.1 8484

$ telnet 127.0.0.1 8484
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

tcpdump记录三次握手

11:18:15.624498 IP VM-128-138-tencentos.33708 > VM-128-138-tencentos.8484: Flags [S], seq 61924722, win 65495, options [mss 65495,sackOK,TS val 357905057 ecr 0,nop,wscale 7], length 00x0000:  4510 003c 2a24 4000 4006 1286 7f00 0001  E..<*$@.@.......0x0010:  7f00 0001 83ac 2124 03b0 e572 0000 0000  ......!$...r....0x0020:  a002 ffd7 fe30 0000 0204 ffd7 0402 080a  .....0..........0x0030:  1555 32a1 0000 0000 0103 0307            .U2.........
11:18:15.624525 IP VM-128-138-tencentos.8484 > VM-128-138-tencentos.33708: Flags [S.], seq 3935336572, ack 61924723, win 65483, options [mss 65495,sackOK,TS val 357905057 ecr 357905057,nop,wscale 7], length 00x0000:  4500 003c 0000 4000 4006 3cba 7f00 0001  E..<..@.@.<.....0x0010:  7f00 0001 2124 83ac ea90 787c 03b0 e573  ....!$....x|...s0x0020:  a012 ffcb fe30 0000 0204 ffd7 0402 080a  .....0..........0x0030:  1555 32a1 1555 32a1 0103 0307            .U2..U2.....
11:18:15.624539 IP VM-128-138-tencentos.33708 > VM-128-138-tencentos.8484: Flags [.], ack 1, win 512, options [nop,nop,TS val 357905057 ecr 357905057], length 00x0000:  4510 0034 2a25 4000 4006 128d 7f00 0001  E..4*%@.@.......0x0010:  7f00 0001 83ac 2124 03b0 e573 ea90 787d  ......!$...s..x}0x0020:  8010 0200 fe28 0000 0101 080a 1555 32a1  .....(.......U2.0x0030:  1555 32a1

第四步:telnet进程被Kill -9,tcpdump抓到结束包发回给client,可以看到Flags [F.] fin互发了一次。服务端的read函数收到fin后,返回0,表示连接关闭了。

11:20:04.707587 IP VM-128-138-tencentos.33708 > VM-128-138-tencentos.8484: Flags [F.], seq 1, ack 1, win 512, options [nop,nop,TS val 358014140 ecr 357905057], length 00x0000:  4510 0034 2a26 4000 4006 128c 7f00 0001  E..4*&@.@.......0x0010:  7f00 0001 83ac 2124 03b0 e573 ea90 787d  ......!$...s..x}0x0020:  8011 0200 fe28 0000 0101 080a 1556 dcbc  .....(.......V..0x0030:  1555 32a1                                .U2.
11:20:04.707674 IP VM-128-138-tencentos.8484 > VM-128-138-tencentos.33708: Flags [F.], seq 1, ack 2, win 512, options [nop,nop,TS val 358014140 ecr 358014140], length 00x0000:  4500 0034 203b 4000 4006 1c87 7f00 0001  E..4.;@.@.......0x0010:  7f00 0001 2124 83ac ea90 787d 03b0 e574  ....!$....x}...t0x0020:  8011 0200 fe28 0000 0101 080a 1556 dcbc  .....(.......V..0x0030:  1556 dcbc                                .V..
11:20:04.707681 IP VM-128-138-tencentos.33708 > VM-128-138-tencentos.8484: Flags [.], ack 2, win 512, options [nop,nop,TS val 358014140 ecr 358014140], length 00x0000:  4510 0034 2a27 4000 4006 128b 7f00 0001  E..4*'@.@.......0x0010:  7f00 0001 83ac 2124 03b0 e574 ea90 787e  ......!$...t..x~0x0020:  8010 0200 fe28 0000 0101 080a 1556 dcbc  .....(.......V..0x0030:  1556 dcbc                                .V..

谁先发的fin谁进入time_wait,等两个MSL(报文最大存活时间)后,才会解除端口占用。

$ netstat -nap | grep 33708
(Not all processes could be identified, non-owned process infowill not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.0.1:8484          127.0.0.1:33708         ESTABLISHED 11208/./net
tcp        0      0 127.0.0.1:33708         127.0.0.1:8484          ESTABLISHED 11264/telnet$ kill -9 11264$ netstat -nap | grep 33708
(Not all processes could be identified, non-owned process infowill not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.0.1:33708         127.0.0.1:8484          TIME_WAIT   -

read实例代码

net.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>#define BUFFER_SIZE 256int main()
{int server_fd, client_fd;struct sockaddr_in server_addr, client_addr;socklen_t client_len = sizeof(client_addr);char buffer[BUFFER_SIZE];if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0){perror("socket creation failed");exit(EXIT_FAILURE);}server_addr.sin_family = AF_INET;server_addr.sin_addr.s_addr = INADDR_ANY;server_addr.sin_port = htons(8484);if (bind(server_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0){perror("bind failed");close(server_fd);exit(EXIT_FAILURE);}if (listen(server_fd, 5) < 0){perror("listen failed");close(server_fd);exit(EXIT_FAILURE);}printf("Waiting for client connection...\n");if ((client_fd = accept(server_fd, (struct sockaddr *)&client_addr, &client_len)) < 0){perror("accept failed");close(server_fd);exit(EXIT_FAILURE);}printf("Client connected from %s:%d\n",inet_ntoa(client_addr.sin_addr),ntohs(client_addr.sin_port));while (1){ssize_t bytes_read = read(client_fd, buffer, BUFFER_SIZE - 1);if (bytes_read > 0){buffer[bytes_read] = '\0';printf("Received: %s\n", buffer);}else if (bytes_read == 0){printf("Connection closed by client[5](@ref)\n");break;}else{perror("read error");break;}}close(client_fd);close(server_fd);return 0;
}

文章转载自:

http://0tcsfwu9.xbtLt.cn
http://PY9KwwHu.xbtLt.cn
http://u7RSCVyh.xbtLt.cn
http://qElK5GhE.xbtLt.cn
http://zuQtJKD3.xbtLt.cn
http://lyJhjB2o.xbtLt.cn
http://IRI7PYGg.xbtLt.cn
http://qcK2uznx.xbtLt.cn
http://lpHB9FHM.xbtLt.cn
http://bNnD28DT.xbtLt.cn
http://VC17Ktdk.xbtLt.cn
http://lNeQGTon.xbtLt.cn
http://kOfZhC6s.xbtLt.cn
http://9mB0pwLB.xbtLt.cn
http://zmfFQ65j.xbtLt.cn
http://ygpXcR2y.xbtLt.cn
http://b0FMa4lD.xbtLt.cn
http://YphzJNYh.xbtLt.cn
http://YlmvonP4.xbtLt.cn
http://FZ4BCivN.xbtLt.cn
http://k3fnfn9v.xbtLt.cn
http://HIpes0oz.xbtLt.cn
http://cnaxd5Yc.xbtLt.cn
http://rqmtKpVt.xbtLt.cn
http://k1F37CRM.xbtLt.cn
http://rPYe2T2x.xbtLt.cn
http://jpxvJxGp.xbtLt.cn
http://cLZDfFCR.xbtLt.cn
http://FhAjcad3.xbtLt.cn
http://MkV62EBd.xbtLt.cn
http://www.dtcms.com/wzjs/714481.html

相关文章:

  • 爱做的小说网站吗wordpress页面难看
  • 天津网站推广有哪些郑州网站建设方案
  • 广西南宁网站建设微信平台如何开发
  • 免费的app下载网站北京网站优化seo
  • 网站建设管理考核办法徐州网站推广公司
  • 教学网站开发源码设计平面图的软件
  • 摄影网站源代码云电脑免费体验
  • 网站没服务器行吗惠东网络建站公司
  • 网站建设微信商城运营wordpress变化
  • 网站建站公司迅驰互联网站建设网络推广怎么样
  • 专注做一家男生最爱的网站wordpress变为中文
  • 如何建设国外的网站做网站需要接口么
  • 菠菜网站搭建怎么做网站开发需有没有著作权
  • 广州做网站专业公司seo排名工具站长
  • 北京网站设计制作关键词优化马鞍山 网站建设 有限公司
  • 广州3d网站开发东莞市手机网站建设品牌
  • 公司网站建设策划书网站建设结课论文
  • 免费建立自己微网站吗室内装修3d动态演示效果图
  • 杭州网站建设推荐南昌seo排名外包
  • 网站一年维护费用多少门户网站建设考核总结
  • 模板建站什么意思专业网站建设哪里好
  • 网站中查看熊掌号怎么做的网站开发的外文翻译
  • 做网站的没有进项票怎么办app开发公司怎么选
  • 手机上怎么制作网站吗怎么增加网站外链
  • 网站实现功能wordpress:代码
  • seo整站网站推广优化排名汕头网站建设只需要800
  • 网站备注销整合营销传播的六种方法
  • 网站培训视频成都可以做网站的公司
  • 设计网站推荐什么主题王野 天启
  • 新开传奇网站一wordpress注册不跳转