[UNIX] Simplify the file descriptor handling in SharedMemory
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Apr 2015 07:28:48 +0000 (07:28 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Apr 2015 07:28:48 +0000 (07:28 +0000)
commita4bb4aa63bcd5deae67be6ab47d4c3182ed34ee0
tree4d2ce26a2767f82bbf3e80e7c0c8dceb0b70cef1
parentca7f8b2f050dcff3a9abf1fd35fa7b2d8f59f43a
[UNIX] Simplify the file descriptor handling in SharedMemory
https://bugs.webkit.org/show_bug.cgi?id=144046

Reviewed by Darin Adler.

Simplify the file descriptor handling and clarify its ownership by
using IPC::Attachment in SharedMemory::Handle instead of fd and
size members. SharedMemory::Handle::adoptFromAttachment() has been
renamed as SharedMemory::Handle::adoptAttachment() and receives an
IPC::Attachment. And SharedMemory::Handle::releaseToAttachment()
has been renamed as SharedMemory::Handle::releaseAttachment().

* Platform/IPC/Attachment.h: Add move constructor and move assigned operator.
* Platform/IPC/Connection.h:
(IPC::Connection::identifierIsNull): A file descriptor is null
when it's -1 no 0.
* Platform/IPC/unix/AttachmentUnix.cpp:
(IPC::Attachment::Attachment):
(IPC::Attachment::operator=):
(IPC::Attachment::dispose): Reset the file descriptor after
closing it.
* Platform/IPC/unix/ConnectionUnix.cpp:
(IPC::Connection::processMessage): Use
SharedMemory::Handle::adoptAttachment() that receives an
IPC::Attachment now.
(IPC::Connection::sendOutgoingMessage): Use
SharedMemory::Handle::releaseAttachment().
* Platform/SharedMemory.h:
* Platform/unix/SharedMemoryUnix.cpp:
(WebKit::SharedMemory::Handle::Handle): Remove initializers for
file descriptor and size members.
(WebKit::SharedMemory::Handle::clear): Dispose the attachment.
(WebKit::SharedMemory::Handle::isNull): Handle is null if the
attachment file descriptor is -1.
(WebKit::SharedMemory::Handle::encode): Use releaseAttachment().
(WebKit::SharedMemory::Handle::decode): Use adoptAttachment().
(WebKit::SharedMemory::Handle::releaseAttachment): Implement it
using move.
(WebKit::SharedMemory::Handle::adoptAttachment): Ditto.
(WebKit::SharedMemory::map): Use
IPC::Attachment::releaseFileDescriptor() instead of manually
changing the member.
(WebKit::SharedMemory::createHandle): Initialize the handle
attachment with the duplicated file descriptor and size.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183176 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebKit2/ChangeLog
Source/WebKit2/Platform/IPC/Attachment.h
Source/WebKit2/Platform/IPC/Connection.h
Source/WebKit2/Platform/IPC/unix/AttachmentUnix.cpp
Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp
Source/WebKit2/Platform/SharedMemory.h
Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp