I'm trying to implement the onSocketOption
delegate for a Curl's HTTP object (http://erdani.com/d/phobos-prerelease/std_net_curl.html#.Curl.onSocketOption).
int onSocketOption(curl_socket_t socketfd,
CurlSockType type) {
import std.socket:Socket, SocketOptionLevel, SocketOption, Linger, AddressFamily;
Socket sock = new Socket(socketfd, AddressFamily.INET);
Linger lingerOpt;
lingerOpt.on = 0;
lingerOpt.time = 0;
sock.setOption(SocketOptionLevel.SOCKET,
SocketOption.LINGER,
lingerOpt);
return 0;
};
Sometimes It seems to work, sometimes I get std.socket.SocketOSException@/tmp/ldc.build/ldc/runtime/phobos/std/socket.d(3175): Unable to set socket option: Bad file descriptor
Is there another way to use that "curl_socket_t"? Its an alias of socket_t
which in turn should just be a regular socket fd (running on linux)
Notice that HTTP doesn't have that callback, so I have a fork of std.net.curl that adds that interface to the "Protocol" mixin in curl.d:
@property void onSocketOption(int delegate(curl_socket_t,
CurlSockType) callback)
{
p.curl.onSocketOption = callback;
}