krb5_net_read(), krb5_net_write() nad krb5_storage_from_fd() should accept both sockets and fds
When a socket and a file descriptor aren't interchangeable, these functions should be able to determine whether it has received one or the other and act accordingly. This assumes that a fd can be cast into a SOCKET.
This commit is contained in:

committed by
Love Hornquist Astrand

parent
67e1aa5109
commit
39f6fc00f8
@@ -41,5 +41,19 @@ krb5_net_read (krb5_context context,
|
|||||||
{
|
{
|
||||||
SOCKET fd = *((SOCKET *)p_fd);
|
SOCKET fd = *((SOCKET *)p_fd);
|
||||||
|
|
||||||
|
#ifdef SOCKET_IS_NOT_AN_FD
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
{
|
||||||
|
HANDLE h = _get_osfhandle(fd);
|
||||||
|
|
||||||
|
if (h != INVALID_HANDLE_VALUE) {
|
||||||
|
return net_read (fd, buf, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error Don't know how to handle socket that may be an fd
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
return net_read_s (fd, buf, len);
|
return net_read_s (fd, buf, len);
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,20 @@ krb5_net_write (krb5_context context,
|
|||||||
{
|
{
|
||||||
SOCKET fd = *((SOCKET *)p_fd);
|
SOCKET fd = *((SOCKET *)p_fd);
|
||||||
|
|
||||||
|
#ifdef SOCKET_IS_NOT_AN_FD
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
{
|
||||||
|
HANDLE h = _get_osfhandle(fd);
|
||||||
|
|
||||||
|
if (h != INVALID_HANDLE_VALUE) {
|
||||||
|
return net_write (fd, buf, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error Don't know how to handle SOCKET that may be an fd
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
return net_write_s (fd, buf, len);
|
return net_write_s (fd, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -86,11 +86,25 @@ fd_free(krb5_storage * sp)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
KRB5_LIB_FUNCTION krb5_storage * KRB5_LIB_CALL
|
KRB5_LIB_FUNCTION krb5_storage * KRB5_LIB_CALL
|
||||||
krb5_storage_from_fd(int fd)
|
krb5_storage_from_fd(SOCKET fd_in)
|
||||||
{
|
{
|
||||||
krb5_storage *sp;
|
krb5_storage *sp;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
#ifdef SOCKET_IS_NOT_AN_FD
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
if (_get_osfhandle(fd_in) != -1) {
|
||||||
|
fd = dup(fd_in);
|
||||||
|
} else {
|
||||||
|
fd = _open_osfhandle(fd_in, 0);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error Don't know how to deal with fd that may or may not be a socket.
|
||||||
|
#endif
|
||||||
|
#else /* SOCKET_IS_NOT_AN_FD */
|
||||||
|
fd = dup(fd_in);
|
||||||
|
#endif
|
||||||
|
|
||||||
fd = dup(fd);
|
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user