mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Made struct a standard built-in module; added string args to {set,get}sockopt;
added gl.gversion().
This commit is contained in:
parent
4526f379bc
commit
aee087946d
3 changed files with 63 additions and 18 deletions
|
@ -27,12 +27,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
/* These modules are normally always included, but *may* be taken out */
|
||||
#define USE_GRP 1 /* Use together with pwd */
|
||||
#define USE_MARSHAL 1 /* This is linked anyway */
|
||||
#define USE_MATH 1
|
||||
#define USE_PWD 1 /* Use together with grp */
|
||||
#define USE_POSIX 1
|
||||
#define USE_SELECT 1
|
||||
#define USE_SOCKET 1
|
||||
#define USE_STRUCT 1
|
||||
#define USE_TIME 1
|
||||
#define USE_MATH 1
|
||||
|
||||
#include "PROTO.h"
|
||||
#include "mymalloc.h"
|
||||
|
@ -318,7 +319,7 @@ struct {
|
|||
{"stdwin", initstdwin},
|
||||
#endif
|
||||
|
||||
#ifdef USE_STRUCT
|
||||
#ifdef USE_STROP
|
||||
{"strop", initstrop},
|
||||
#endif
|
||||
|
||||
|
|
|
@ -801,6 +801,18 @@ gl_unpackrect(self, args)
|
|||
return unpacked;
|
||||
}
|
||||
|
||||
% gversion
|
||||
static object *
|
||||
gl_gversion(self, args)
|
||||
object *self;
|
||||
object *args;
|
||||
{
|
||||
char buf[20];
|
||||
gversion(buf);
|
||||
return newstringobject(buf);
|
||||
}
|
||||
|
||||
|
||||
/* End of manually written stubs */
|
||||
|
||||
%%
|
||||
|
|
|
@ -384,8 +384,10 @@ sock_allowbroadcast(s, args)
|
|||
}
|
||||
|
||||
|
||||
/* s.setsockopt() method */
|
||||
/* XXX this works for integer flags only */
|
||||
/* s.setsockopt() method.
|
||||
With an integer third argument, sets an integer option.
|
||||
With a string third argument, sets an option from a buffer;
|
||||
use optional built-in module 'struct' to encode the string. */
|
||||
|
||||
static object *
|
||||
sock_setsockopt(s, args)
|
||||
|
@ -394,12 +396,21 @@ sock_setsockopt(s, args)
|
|||
{
|
||||
int level;
|
||||
int optname;
|
||||
int flag;
|
||||
int res;
|
||||
char *buf;
|
||||
int buflen;
|
||||
int flag;
|
||||
|
||||
if (!getargs(args, "(iii)", &level, &optname, &flag))
|
||||
return NULL;
|
||||
res = setsockopt(s->sock_fd, level, optname, &flag, sizeof flag);
|
||||
if (getargs(args, "(iii)", &level, &optname, &flag)) {
|
||||
buf = (char *) &flag;
|
||||
buflen = sizeof flag;
|
||||
}
|
||||
else {
|
||||
err_clear();
|
||||
if (!getargs(args, "(iis#)", &level, &optname, &buf, &buflen))
|
||||
return NULL;
|
||||
}
|
||||
res = setsockopt(s->sock_fd, level, optname, buf, buflen);
|
||||
if (res < 0)
|
||||
return socket_error();
|
||||
INCREF(None);
|
||||
|
@ -407,8 +418,10 @@ sock_setsockopt(s, args)
|
|||
}
|
||||
|
||||
|
||||
/* s.getsockopt() method */
|
||||
/* XXX this works for integer flags only */
|
||||
/* s.getsockopt() method.
|
||||
With two arguments, retrieves an integer option.
|
||||
With a third integer argument, retrieves a string buffer of that size;
|
||||
use optional built-in module 'struct' to decode the string. */
|
||||
|
||||
static object *
|
||||
sock_getsockopt(s, args)
|
||||
|
@ -417,18 +430,37 @@ sock_getsockopt(s, args)
|
|||
{
|
||||
int level;
|
||||
int optname;
|
||||
int flag;
|
||||
int flagsize;
|
||||
int res;
|
||||
object *buf;
|
||||
int buflen;
|
||||
int flag;
|
||||
|
||||
if (!getargs(args, "(ii)", &level, &optname))
|
||||
if (getargs(args, "(ii)", &level, &optname)) {
|
||||
int flag = 0;
|
||||
int flagsize = sizeof flag;
|
||||
res = getsockopt(s->sock_fd, level, optname, &flag, &flagsize);
|
||||
if (res < 0)
|
||||
return socket_error();
|
||||
return newintobject(flag);
|
||||
}
|
||||
err_clear();
|
||||
if (!getargs(args, "(iii)", &level, &optname, &buflen))
|
||||
return NULL;
|
||||
flagsize = sizeof flag;
|
||||
flag = 0;
|
||||
res = getsockopt(s->sock_fd, level, optname, &flag, &flagsize);
|
||||
if (res < 0)
|
||||
if (buflen <= 0 || buflen > 1024) {
|
||||
err_setstr(SocketError, "getsockopt buflen out of range");
|
||||
return NULL;
|
||||
}
|
||||
buf = newsizedstringobject((char *)NULL, buflen);
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
res = getsockopt(s->sock_fd, level, optname, getstringvalue(buf),
|
||||
&buflen);
|
||||
if (res < 0) {
|
||||
DECREF(buf);
|
||||
return socket_error();
|
||||
return newintobject(flag);
|
||||
}
|
||||
resizestring(&buf, buflen);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue