mesos-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benjamin Mahler <bmah...@apache.org>
Subject Re: Please use `int_fd` instead of `int` for file descriptors
Date Fri, 01 Dec 2017 00:41:30 GMT
On Thu, Nov 30, 2017 at 11:12 PM, Andrew Schwartzmeyer <
andrew@schwartzmeyer.com> wrote:

> For Linux it is literally an `int`:
>
> using int_fd = int;
>>
>
> https://github.com/apache/mesos/blob/bf4bc6380cb99132736fbbe
> fc85f3a7ca60b032c/3rdparty/stout/include/stout/os/int_fd.hpp#L35
>
>
Yes I realize that :)


> So it's a safe drop-in replacement on non-Windows platforms, with all the
> same properties of an `int`.
>
> It's only on Windows where it is instead `os::WindowsFD`, and then you may
> need to worry about its properties and semantics. Do you want these
> documented in `stout/os/windows/fd.hpp`?


Yes, we have code using int_fd within hashmaps, maps, etc, already across
platforms so I assume it has the properties I listed on windows, but it
would be good to document that as being something that int_fd is guaranteed
to provide.


>
>
> On 11/30/2017 3:05 pm, Benjamin Mahler wrote:
>
>> Is it possible to document in that header the properties of int_fd that we
>> can rely on?
>>
>> For example, it has a hash defined for use in unordered map, set, etc.
>> It's
>> a POD type, etc.
>>
>> On Wed, Nov 29, 2017 at 10:17 PM, Andrew Schwartzmeyer <
>> andrew@schwartzmeyer.com> wrote:
>>
>> Hello everyone!
>>>
>>> I've realized that a lot of developers working in libprocess (and
>>> elsewhere) may not know about how to handle file descriptors in a
>>> cross-platform way for Mesos.
>>>
>>> IMPORTANT: You cannot just use `int`. File descriptors on Windows are
>>> various types of handles, but not just an `int`.
>>>
>>> The abstraction we use in Mesos is `int_fd`, found here:
>>> https://github.com/apache/mesos/blob/master/3rdparty/stout/
>>> include/stout/os/int_fd.hpp
>>>
>>> On non-Windows platforms, it's just an `int`. But on Windows, it's a
>>> `WindowsFD` which can be an `int` (from the Windows CRT which we're
>>> deprecating), a `HANDLE` (the Windows 32 API), and a `SOCKET` (from the
>>> WinSock library). If you're curious, the implementation is here:
>>> https://github.com/apache/mesos/blob/master/3rdparty/stout/
>>> include/stout/os/windows/fd.hpp
>>>
>>> I just want you to be aware that if you're writing code and need an `int`
>>> file descriptor, please use `int_fd` (and include the appropriate header)
>>> instead of `int`, as otherwise you break the Windows build.
>>>
>>> Thank you,
>>>
>>> Andy
>>>
>>>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message