[ace-users] ACE_FILE_LOCK using handle owned by ACE_FILE_LOCK

Gudugunta, Sukumar Sukumar.Gudugunta at philips.com
Tue Feb 2 13:58:30 CST 2016


Hi All

We are using ACE_FILE_LOCK object to lock the file (read/write). Here am using   set handle (ACE_HANDLE) method to set the handle for the lock.
Can anyone let me know why we need to set this handle?

Once we acquire the lock can I use the same handle to truncate and rewrite the whole file? Does it cause any dead locks?

int err= 0;
  err = ACE_OS::ftruncate(m_lock.get_handle(),0);
  //Here we have opened the two handles(Open method) above. using m_handle we can't overwrite first byts of the file
  //Since the iFileLocK mechanism locks the first byte of the file.hence using the handle owned by m_lock to overwrite the entire file
  ACE_UINT64 qwPosition = 0;
  if(!Stentor::FileSeek(m_lock.get_handle(),offset,FILE_BEGIN, qwPosition))
    throw OSError("FileSeek failed",m_path.c_str(),THISFILE,__LINE__);

  if(ACE_OS::write(m_lock.get_handle(),buffer,size)!=size)
  throw OSError("Write failed",m_path.c_str(),THISFILE,__LINE__);


As per my understanding ACE_FILE_LOCK locks the offset of first byte in the file. Please let me know if this is correct?
Thanks in advance

-Sukumar

________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.


More information about the ace-users mailing list