![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Sorry to revive this thread, but I have a question that I think should be included in this thread.
The client utility (mentioned in first post) that the users will have writes to a single file. With 90+ users it is inevitable that multiple people could be trying to write (add service call) to the file at the same time. Before I deploy this program, I would like to add a function that will check the .DAT file to see if it is currently being edited before the actual write process begins. I would greatly appreciate any info that can be provided on the creation of this function. Links, tutorials, etc. Thanks, -BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#12 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 850
Rep Power: 4
![]() |
How are you opening the file at the moment in the utility?
If you are using ofstreams, you could add a sharing parameter to the open call or to the constructor call. _SH_DENYWR will stop others from opening the file for write at the same time. You would then just have to handle the case where the utility couldn't open the file, e.g. by waiting for a bit and then retrying. Note: I haven't tried this, so it could be all wrong. |
|
|
|
|
|
#13 | |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Quote:
Thanks, -BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
|
#14 |
|
Guest
Posts: n/a
|
Some programs won't write to files properly if another program already has a file open. Forger told me that.
|
|
|
|
#15 | |
|
Professional Programmer
|
Quote:
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
|
#16 | |
|
Expert Programmer
Join Date: Jun 2005
Posts: 850
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#17 | |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Quote:
I think The Dark's solution will work, I just need to finish editing the code. The only question I have so far is, do I have to turn off the write lock? Or will that happen when the file is closed? Thanks for the help. -BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
|
#18 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 850
Rep Power: 4
![]() |
It will happen when the file is closed.
|
|
|
|
|
|
#19 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
I got this to work as I wanted by initiating the lock immediatly after the program writes to the file for a short period of time. I noticed through trial and error that this was the vulnerable time when data loss happened during very close consecutive writes. I have tested this method quite extensively and have not experienced any data loss thus far with the lock in place.
Please let me know if this might present other problems I am not aware of. Thanks for the help The Dark. -BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|