Cygwin: convert sun_name_t into class
Add constructors and new/delete operators to make sure sun_name_t objects are allocated on the cygheap. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
aa467e6e33
commit
dc3928fc75
|
@ -817,8 +817,9 @@ class fhandler_socket_local: public fhandler_socket_wsock
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sun_name_t
|
class sun_name_t
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
__socklen_t un_len;
|
__socklen_t un_len;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
@ -826,6 +827,22 @@ struct sun_name_t
|
||||||
/* Allows 108 bytes sun_path plus trailing NUL */
|
/* Allows 108 bytes sun_path plus trailing NUL */
|
||||||
char _nul[sizeof (struct sockaddr_un) + 1];
|
char _nul[sizeof (struct sockaddr_un) + 1];
|
||||||
};
|
};
|
||||||
|
sun_name_t ()
|
||||||
|
{
|
||||||
|
un_len = 0;
|
||||||
|
un.sun_family = 0;
|
||||||
|
_nul[sizeof (struct sockaddr_un)] = '\0';
|
||||||
|
}
|
||||||
|
sun_name_t (const struct sockaddr *name, __socklen_t namelen)
|
||||||
|
{
|
||||||
|
un_len = namelen < (__socklen_t) sizeof un ? namelen : sizeof un;
|
||||||
|
memcpy (&un, name, un_len);
|
||||||
|
_nul[sizeof (struct sockaddr_un)] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
void *operator new (size_t) __attribute__ ((nothrow))
|
||||||
|
{ return cmalloc_abort (HEAP_FHANDLER, sizeof (sun_name_t)); }
|
||||||
|
void operator delete (void *p) {cfree (p);}
|
||||||
};
|
};
|
||||||
|
|
||||||
class fhandler_socket_unix : public fhandler_socket
|
class fhandler_socket_unix : public fhandler_socket
|
||||||
|
|
|
@ -158,9 +158,9 @@ fhandler_socket_unix::fhandler_socket_unix () :
|
||||||
fhandler_socket_unix::~fhandler_socket_unix ()
|
fhandler_socket_unix::~fhandler_socket_unix ()
|
||||||
{
|
{
|
||||||
if (sun_path)
|
if (sun_path)
|
||||||
cfree (sun_path);
|
delete sun_path;
|
||||||
if (peer_sun_path)
|
if (peer_sun_path)
|
||||||
cfree (peer_sun_path);
|
delete peer_sun_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -168,11 +168,7 @@ fhandler_socket_unix::set_sun_path (struct sockaddr_un *un, socklen_t unlen)
|
||||||
{
|
{
|
||||||
if (!un)
|
if (!un)
|
||||||
sun_path = NULL;
|
sun_path = NULL;
|
||||||
sun_path = (struct sun_name_t *) cmalloc_abort (HEAP_FHANDLER,
|
sun_path = new sun_name_t ((const struct sockaddr *) un, unlen);
|
||||||
sizeof *sun_path);
|
|
||||||
sun_path->un_len = unlen;
|
|
||||||
memcpy (&sun_path->un, un, sizeof (*un));
|
|
||||||
sun_path->_nul[sizeof (struct sockaddr_un)] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -181,11 +177,7 @@ fhandler_socket_unix::set_peer_sun_path (struct sockaddr_un *un,
|
||||||
{
|
{
|
||||||
if (!un)
|
if (!un)
|
||||||
peer_sun_path = NULL;
|
peer_sun_path = NULL;
|
||||||
peer_sun_path = (struct sun_name_t *) cmalloc_abort (HEAP_FHANDLER,
|
peer_sun_path = new sun_name_t ((const struct sockaddr *) un, unlen);
|
||||||
sizeof *peer_sun_path);
|
|
||||||
peer_sun_path->un_len = unlen;
|
|
||||||
memcpy (&peer_sun_path->un, un, sizeof (*un));
|
|
||||||
peer_sun_path->_nul[sizeof (struct sockaddr_un)] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue