c - fwrite() 没有完成写入文件
问题描述
试图将文件从客户端发送到服务器。
这是我收到它的方式:
printf("Server receiving file...\n");
while((bytes_read = read(sd, buf, sizeof(buf))) > 0){ //second read now retrieving the file size
printf("writing");
fwrite(buf, 1, bytes_read, fp);
printf("checking if reached here");
}
出于某种原因,第二个打印语句“检查是否到达这里”永远不会到达,并且程序只是没有退出循环。可能是什么问题?
PS。我的客户发送所有字节,因此发送没有问题。它只是写入文件
解决方案
套接字是否阻塞(默认)?
如果是,则只要没有数据可读取,read() 就会挂起,等待更多数据(或等待套接字关闭,在这种情况下它将返回 0 字节)。
推荐阅读
- c# - 在文本中查找评论并使用正则表达式替换它们
- mysql - 修改 SQL 查询以仅获取过去 2 个月的数据
- google-docs-api - 如何通过 google-docs-api 请求向表格单元格添加内容?
- php - 安装和设置 october cms 期间的问题
- javascript - 搜索从 .cshtml 文件调用的 javascript 函数时在 ASP.NET MVC 项目中查找的位置和文件
- imap - 如何使用 fetchmail / procmail 删除 IMAP 邮件
- python - AttributeError: 'list' 对象在 TF-IDF 中没有属性 'lower'
- forms - 我们如何在 Workfront 中发布来自多个类别的自定义字段
- node.js - MongoDb 基于数组元素的聚合条件
- c# - Linq to Entities - 在 lambda 表达式中转换数据类型