예제 #1
0
static PyObject *py_socket_close(pytalloc_Object *self, PyObject *args)
{
	int *sock;
	int status;

	sock = pytalloc_get_ptr(self);

	status = swrap_close(*sock);
	if (status < 0) {
		return PyErr_SetFromErrno(py_socket_error);
	}

	Py_RETURN_NONE;
}
예제 #2
0
_PUBLIC_ int swrap_dup2(int oldd, int newd)
{
	struct socket_info *si_newd, *si_oldd;
	int fd;

	if (newd == oldd)
	    return newd;

	si_oldd = find_socket_info(oldd);
	si_newd = find_socket_info(newd);

	if (si_oldd == NULL && si_newd == NULL)
		return real_dup2(oldd, newd);

	fd = real_dup2(si_oldd->fd, newd);
	if (fd < 0)
		return fd;

	/* close new socket first */
	if (si_newd)
	       	swrap_close(newd);

	return dup_internal(si_oldd, fd);
}