mirror of
https://github.com/dlang/phobos.git
synced 2025-05-02 08:00:48 +03:00
Merge r355:385 from branches/phobos-1.x to trunk
-- fix for bug 1491 -- sigpipe suppression -- fix for bug 1478 -- libc network api threadsafety -- add std.socket to the standard unittest set
This commit is contained in:
parent
7b5380e64f
commit
e665d910ca
4 changed files with 17 additions and 7 deletions
|
@ -236,6 +236,7 @@ enum: int
|
||||||
MSG_OOB = 0x1,
|
MSG_OOB = 0x1,
|
||||||
MSG_PEEK = 0x2,
|
MSG_PEEK = 0x2,
|
||||||
MSG_DONTROUTE = 0x4,
|
MSG_DONTROUTE = 0x4,
|
||||||
|
MSG_NOSIGNAL = 0x4000,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -381,6 +381,7 @@ enum: int
|
||||||
MSG_OOB = 0x1,
|
MSG_OOB = 0x1,
|
||||||
MSG_PEEK = 0x2,
|
MSG_PEEK = 0x2,
|
||||||
MSG_DONTROUTE = 0x4,
|
MSG_DONTROUTE = 0x4,
|
||||||
|
MSG_NOSIGNAL = 0x0, /// not supported on win32, would be 0x4000 if it was
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
15
std/socket.d
15
std/socket.d
|
@ -453,7 +453,8 @@ class InternetHost
|
||||||
*/
|
*/
|
||||||
bool getHostByName(string name)
|
bool getHostByName(string name)
|
||||||
{
|
{
|
||||||
hostent* he = gethostbyname(toStringz(name));
|
hostent* he;
|
||||||
|
synchronized he = gethostbyname(toStringz(name));
|
||||||
if(!he)
|
if(!he)
|
||||||
return false;
|
return false;
|
||||||
validHostent(he);
|
validHostent(he);
|
||||||
|
@ -468,7 +469,8 @@ class InternetHost
|
||||||
bool getHostByAddr(uint addr)
|
bool getHostByAddr(uint addr)
|
||||||
{
|
{
|
||||||
uint x = htonl(addr);
|
uint x = htonl(addr);
|
||||||
hostent* he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
hostent* he;
|
||||||
|
synchronized he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
||||||
if(!he)
|
if(!he)
|
||||||
return false;
|
return false;
|
||||||
validHostent(he);
|
validHostent(he);
|
||||||
|
@ -485,7 +487,8 @@ class InternetHost
|
||||||
bool getHostByAddr(string addr)
|
bool getHostByAddr(string addr)
|
||||||
{
|
{
|
||||||
uint x = inet_addr(std.string.toStringz(addr));
|
uint x = inet_addr(std.string.toStringz(addr));
|
||||||
hostent* he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
hostent* he;
|
||||||
|
synchronized he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
||||||
if(!he)
|
if(!he)
|
||||||
return false;
|
return false;
|
||||||
validHostent(he);
|
validHostent(he);
|
||||||
|
@ -731,6 +734,7 @@ enum SocketFlags: int
|
||||||
OOB = MSG_OOB, /// out-of-band stream data
|
OOB = MSG_OOB, /// out-of-band stream data
|
||||||
PEEK = MSG_PEEK, /// peek at incoming data without removing it from the queue, only for receiving
|
PEEK = MSG_PEEK, /// peek at incoming data without removing it from the queue, only for receiving
|
||||||
DONTROUTE = MSG_DONTROUTE, /// data should not be subject to routing; this flag may be ignored. Only for sending
|
DONTROUTE = MSG_DONTROUTE, /// data should not be subject to routing; this flag may be ignored. Only for sending
|
||||||
|
NOSIGNAL = MSG_NOSIGNAL, /// don't send SIGPIPE signal on socket write error and instead return EPIPE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1267,6 +1271,7 @@ class Socket
|
||||||
//returns number of bytes actually sent, or -1 on error
|
//returns number of bytes actually sent, or -1 on error
|
||||||
int send(const(void)[] buf, SocketFlags flags)
|
int send(const(void)[] buf, SocketFlags flags)
|
||||||
{
|
{
|
||||||
|
flags |= SocketFlags.NOSIGNAL;
|
||||||
int sent = .send(sock, buf.ptr, buf.length, cast(int)flags);
|
int sent = .send(sock, buf.ptr, buf.length, cast(int)flags);
|
||||||
return sent;
|
return sent;
|
||||||
}
|
}
|
||||||
|
@ -1274,7 +1279,7 @@ class Socket
|
||||||
/// ditto
|
/// ditto
|
||||||
int send(const(void)[] buf)
|
int send(const(void)[] buf)
|
||||||
{
|
{
|
||||||
return send(buf, SocketFlags.NONE);
|
return send(buf, SocketFlags.NOSIGNAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1282,6 +1287,7 @@ class Socket
|
||||||
*/
|
*/
|
||||||
int sendTo(const(void)[] buf, SocketFlags flags, Address to)
|
int sendTo(const(void)[] buf, SocketFlags flags, Address to)
|
||||||
{
|
{
|
||||||
|
flags |= SocketFlags.NOSIGNAL;
|
||||||
int sent = .sendto(sock, buf.ptr, buf.length, cast(int)flags, to.name(), to.nameLen());
|
int sent = .sendto(sock, buf.ptr, buf.length, cast(int)flags, to.name(), to.nameLen());
|
||||||
return sent;
|
return sent;
|
||||||
}
|
}
|
||||||
|
@ -1297,6 +1303,7 @@ class Socket
|
||||||
/// ditto
|
/// ditto
|
||||||
int sendTo(const(void)[] buf, SocketFlags flags)
|
int sendTo(const(void)[] buf, SocketFlags flags)
|
||||||
{
|
{
|
||||||
|
flags |= SocketFlags.NOSIGNAL;
|
||||||
int sent = .sendto(sock, buf.ptr, buf.length, cast(int)flags, null, 0);
|
int sent = .sendto(sock, buf.ptr, buf.length, cast(int)flags, null, 0);
|
||||||
return sent;
|
return sent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ import std.uni;
|
||||||
import std.file;
|
import std.file;
|
||||||
import std.signals;
|
import std.signals;
|
||||||
import std.cpuid;
|
import std.cpuid;
|
||||||
|
import std.socket;
|
||||||
|
|
||||||
int main(char[][] args)
|
int main(char[][] args)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue