mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
add setblocking(); NT changes; null-terminate Unix path
This commit is contained in:
parent
6e69fc7a72
commit
30b6b2b032
1 changed files with 33 additions and 12 deletions
|
@ -83,6 +83,7 @@ Socket methods:
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#else
|
#else
|
||||||
#include <winsock.h>
|
#include <winsock.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SYS_UN_H
|
#ifdef HAVE_SYS_UN_H
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
@ -103,7 +104,7 @@ Socket methods:
|
||||||
#ifdef NT
|
#ifdef NT
|
||||||
/* seem to be a few differences in the API */
|
/* seem to be a few differences in the API */
|
||||||
#define close closesocket
|
#define close closesocket
|
||||||
#define NO_DUP /* I wont trust passing a socket to NT's RTL!! */
|
#define NO_DUP /* Define for NT 3.1, Win3.1 and Win95, Undefine for NT3.5 */
|
||||||
#define FORCE_ANSI_FUNC_DEFS
|
#define FORCE_ANSI_FUNC_DEFS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -364,6 +365,7 @@ getsockaddrarg,PySocketSockObject *,s, PyObject *,args, struct sockaddr **,addr_
|
||||||
}
|
}
|
||||||
addr->sun_family = AF_UNIX;
|
addr->sun_family = AF_UNIX;
|
||||||
memcpy(addr->sun_path, path, len);
|
memcpy(addr->sun_path, path, len);
|
||||||
|
addr->sun_path[len] = 0;
|
||||||
*addr_ret = (struct sockaddr *) addr;
|
*addr_ret = (struct sockaddr *) addr;
|
||||||
*len_ret = len + sizeof addr->sun_family;
|
*len_ret = len + sizeof addr->sun_family;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -484,32 +486,32 @@ BUILD_FUNC_DEF_2(PySocketSock_allowbroadcast,PySocketSockObject *,s, PyObject *,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef NT
|
|
||||||
|
|
||||||
/* s.setblocking(1 | 0) method */
|
/* s.setblocking(1 | 0) method */
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySocketSock_setblocking(s, args)
|
BUILD_FUNC_DEF_2(PySocketSock_setblocking,PySocketSockObject*,s,PyObject*,args)
|
||||||
PySocketSockObject *s;
|
|
||||||
PyObject *args;
|
|
||||||
{
|
{
|
||||||
int block;
|
int block;
|
||||||
int delay_flag;
|
int delay_flag;
|
||||||
if (!PyArg_GetInt(args, &block))
|
if (!PyArg_GetInt(args, &block))
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
#ifndef NT
|
||||||
delay_flag = fcntl (s->sock_fd, F_GETFL, 0);
|
delay_flag = fcntl (s->sock_fd, F_GETFL, 0);
|
||||||
if (block)
|
if (block)
|
||||||
delay_flag &= (~O_NDELAY);
|
delay_flag &= (~O_NDELAY);
|
||||||
else
|
else
|
||||||
delay_flag |= O_NDELAY;
|
delay_flag |= O_NDELAY;
|
||||||
fcntl (s->sock_fd, F_SETFL, delay_flag);
|
fcntl (s->sock_fd, F_SETFL, delay_flag);
|
||||||
|
#else
|
||||||
|
block = !block;
|
||||||
|
ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block);
|
||||||
|
#endif
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* s.setsockopt() method.
|
/* s.setsockopt() method.
|
||||||
|
@ -740,8 +742,13 @@ BUILD_FUNC_DEF_2(PySocketSock_makefile,PySocketSockObject *,s, PyObject *,args)
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "|si", &mode, &bufsize))
|
if (!PyArg_ParseTuple(args, "|si", &mode, &bufsize))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#ifdef NT
|
||||||
|
if ( ((fd = _open_osfhandle( s->sock_fd, _O_BINARY )) < 0) ||
|
||||||
|
((fd = dup(fd)) < 0) || ((fp = fdopen(fd, mode)) == NULL)) {
|
||||||
|
#else
|
||||||
if ((fd = dup(s->sock_fd)) < 0 ||
|
if ((fd = dup(s->sock_fd)) < 0 ||
|
||||||
(fp = fdopen(fd, mode)) == NULL) {
|
(fp = fdopen(fd, mode)) == NULL) {
|
||||||
|
#endif
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
close(fd);
|
close(fd);
|
||||||
return PySocket_Err();
|
return PySocket_Err();
|
||||||
|
@ -893,9 +900,7 @@ static PyMethodDef PySocketSock_methods[] = {
|
||||||
#if 0
|
#if 0
|
||||||
{"allowbroadcast", (PyCFunction)PySocketSock_allowbroadcast},
|
{"allowbroadcast", (PyCFunction)PySocketSock_allowbroadcast},
|
||||||
#endif
|
#endif
|
||||||
#ifndef NT
|
|
||||||
{"setblocking", (PyCFunction)PySocketSock_setblocking},
|
{"setblocking", (PyCFunction)PySocketSock_setblocking},
|
||||||
#endif
|
|
||||||
{"setsockopt", (PyCFunction)PySocketSock_setsockopt},
|
{"setsockopt", (PyCFunction)PySocketSock_setsockopt},
|
||||||
{"getsockopt", (PyCFunction)PySocketSock_getsockopt},
|
{"getsockopt", (PyCFunction)PySocketSock_getsockopt},
|
||||||
{"bind", (PyCFunction)PySocketSock_bind},
|
{"bind", (PyCFunction)PySocketSock_bind},
|
||||||
|
@ -1461,15 +1466,31 @@ BOOL WINAPI DllMain (HANDLE hInst,
|
||||||
ULONG ul_reason_for_call,
|
ULONG ul_reason_for_call,
|
||||||
LPVOID lpReserved)
|
LPVOID lpReserved)
|
||||||
{
|
{
|
||||||
|
const int opt = SO_SYNCHRONOUS_NONALERT;
|
||||||
switch (ul_reason_for_call)
|
switch (ul_reason_for_call)
|
||||||
{
|
{
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH: {
|
||||||
WSADATA WSAData;
|
WSADATA WSAData;
|
||||||
if (WSAStartup(MAKEWORD(2,0), &WSAData)) {
|
BOOL ok = TRUE;
|
||||||
OutputDebugString("Python can't initialize Windows Sockets DLL!");
|
char buf[100] = "Python can't initialize Windows Sockets Module!\n\r";
|
||||||
|
if (WSAStartup(MAKEWORD(1,1), &WSAData)) {
|
||||||
|
wsprintf(buf+strlen(buf), "WSAStartup failed (%d)",WSAGetLastError());
|
||||||
|
ok = FALSE;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
** Setup sockets in non-overlapped mode by default
|
||||||
|
*/
|
||||||
|
if (ok && setsockopt(INVALID_SOCKET,SOL_SOCKET,SO_OPENTYPE,(const char *)&opt,sizeof(opt)) != 0) {
|
||||||
|
wsprintf(buf+strlen(buf),"setsockopt failed (%d)",WSAGetLastError());
|
||||||
|
ok = FALSE;
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
MessageBox(NULL,buf,"WinSock Error",MB_OK|MB_SETFOREGROUND);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue