文件读写问题,希望多给些意见。

c4489128 2006-03-05 09:54:18
问题描述:
我是做电信行业软件的(联机计费采集)。现在有个棘手的问题,希望大家给些自己的思路,谢谢!
完成巨龙04交换机的实时计费采集,现在是04交换机一天实时的写一个计费文件。现在用户要求做到实时,所以必须在交换机程序写文件的同时我在另一台机器上来读这个文件并分解话单,实时传送给帐务中心。
这里涉及到问题:
1、一个进程在实时写一个文件,而另一个进程要读这个文件,怎么办?
2、要求不改现有的交换机程序,也就是在现有的基础上来完成(04交换机厂家不会因为你而修改交换机程序的,所以没有办法与采集程序做资源同步--否则用文件映射,共享内存应该可以解决的)

希望大家给些思路,真的很棘手啊!!谢谢!
...全文
469 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
gudulyn 2006-05-30
  • 打赏
  • 举报
回复
mark
roger_77 2006-04-05
  • 打赏
  • 举报
回复
我觉得最好使用实时数据库的功能来解决比较好.
实时数据库模块负责实时数据的缓冲,写入文件,并维护其它进程对数据的同步读写.

一般也应该这么实现.
bulala 2006-04-04
  • 打赏
  • 举报
回复
要看 交换机的OS,关于同步的问题,我觉得一个在写,一个在读不会出现问题。至多只是读的不完整罢了。可以在读的逻辑中判断一下。另外也可以将其读出的数据整理后生成一个文件。发送整理后的文件。
herryhuang 2006-04-03
  • 打赏
  • 举报
回复
什么平台?windows还是UNIX/Linux?
zengpan_panpan 2006-03-29
  • 打赏
  • 举报
回复
如果写端以追加模式写.读端尽管读前面的数据啊.读不出来新数据就挂起一小段时间,当然不可能有绝对的实时.

冲突只可能发生在尾部,一个数据块没写完,就被读出来了.通过一些校验,或者分析文件长度和记录大小的关系,就可以解决这个问题.

逸学堂 2006-03-09
  • 打赏
  • 举报
回复
CFile::shareDenyNone
`~`~`~`~`~`~
同意
Squall1009 2006-03-09
  • 打赏
  • 举报
回复
和我们以前做的一个系统比较象,不过我们当时是一个小时采集一次,
当时我们是,到了一定的,时候先把那个记录文件做一个copy,然后清空记录文件.接着再分析那份拷贝.
感觉不可能存在记录文件一直在被写的情况。
不过这个东西做实时的好象是一件让人很郁闷的事情
寻开心 2006-03-07
  • 打赏
  • 举报
回复
msdn里CFile写的很清楚:

CFile::shareDenyNone Opens the file without denying other processes read or write access to the file. Create fails if the file has been opened in compatibility mode by any other process.

CFile::shareDenyRead Opens the file and denies other processes read access to the file. Create fails if the file has been opened in compatibility mode or for read access by any other process.

CFile::shareDenyWrite Opens the file and denies other processes write access to the file. Create fails if the file has been opened in compatibility mode or for write access by any other process.


CFile::shareExclusive Opens the file with exclusive mode, denying other processes both read and write access to the file. Construction fails if the file has been opened in any other mode for read or write access, even by the current process.

直接调用OpenFile,可以不用CFile的
OF_SHARE_COMPAT For MS-DOS–based file systems using the Win32 API, opens the file with compatibility mode, allowing any process on a specified computer to open the file any number of times. Other efforts to open with any other sharing mode fail.
Windows NT/2000: This flag is mapped to the CreateFile function's FILE_SHARE_READ | FILE_SHARE_WRITE flags.

OF_SHARE_DENY_NONE Opens the file without denying read or write access to other processes. On MS-DOS-based file systems using the Win32 API, if the file has been opened in compatibility mode by any other process, the function fails.
Windows NT/2000: This flag is mapped to the CreateFile function's FILE_SHARE_READ | FILE_SHARE_WRITE flags.

OF_SHARE_DENY_READ Opens the file and denies read access to other processes. On MS-DOS-based file systems using the Win32 API, if the file has been opened in compatibility mode or for read access by any other process, the function fails.
Windows NT/2000: This flag is mapped to the CreateFile function's FILE_SHARE_WRITE flag.

OF_SHARE_DENY_WRITE Opens the file and denies write access to other processes. On MS-DOS-based file systems using the Win32 API, if the file has been opened in compatibility mode or for write access by any other process, the function fails.
Windows NT/2000: This flag is mapped to the CreateFile function's FILE_SHARE_READ flag.

OF_SHARE_EXCLUSIVE Opens the file with exclusive mode, denying both read and write access to other processes. If the file has been opened in any other mode for read or write access, even by the current process, the function fails.

寻开心 2006-03-07
  • 打赏
  • 举报
回复
VC/MFC里面的 CFile::shareDenyNone 打开文件读写,不影响其他进程对文件的处理
lbing7 2006-03-07
  • 打赏
  • 举报
回复
1、一个进程在实时写一个文件,而另一个进程要读这个文件,怎么办?

这样的冲突,也许可以用信号量来处理
bohlee 2006-03-07
  • 打赏
  • 举报
回复
mark

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧