Jump to content
  • Advertisement
Sign in to follow this  
jeff8j

flock in windows?

This topic is 2209 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What exactly is it you are trying to do anyway? At most on Window's I used the CreateFile share modes, and on Linux currently I just resort to trusting other processes not to mess with my files. Things like LockFileEx seem to be for locking segments of files, which only seems useful if you are writing a DB like SQLite or something and want multiple independent processes to safely read and write.

Share this post


Link to post
Share on other sites
Advertisement

Im trying to setup a server with sessions where theres multiple processes where they can be reading and writing at the same time. The current setup uses file descriptors ie ints for the files works great in linux! My thoughts are either to get some version of flock working or rewrite the file handling to use the windows api for files ie createfile lockfile and such.

 

If I use lockfileex to lock a segmant I cant get another lock on that segmant so it would effectively block other processes of the same type of course. So I guess maybe a third option is to convert a file descriptor to a winapi file handle? Ill do some looking up on that and see what comes out of it.

Share this post


Link to post
Share on other sites

The conversion seems to have worked well it atleast compiled I need to throughly test it!

LockFile( _get_osfhandle(fd), 0, 0, 1024, 0 )

 

Thanks SyncViews! Ill post if it works the way I need it to or not!

Share this post


Link to post
Share on other sites

Works perfectly took me a bit to test because I forgot it doesnt lock in the same process lol. Hopfully this helps the next person racking there brain and saves some time vs rewriting to use createfile and the windows file handles.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!