|
|
发表于 2005-6-28 19:58:04
|
显示全部楼层
socket的man页有一段说明,这个长度就是一个int型, posix凑了个socklen_t出来。
$ man accept
NOTE
The third argument of accept was originally declared as an `int *' (and is that under libc4 and libc5 and on many other systems
like BSD 4.*, SunOS 4, SGI); a POSIX 1003.1g draft standard wanted to change it into a `size_t *', and that is what it is for SunOS
5. Later POSIX drafts have `socklen_t *', and so do the Single Unix Specification and glibc2. Quoting Linus Torvalds:
"_Any_ sane library _must_ have "socklen_t" be the same size as int. Anything else breaks any BSD socket layer stuff. POSIX ini-
tially _did_ make it a size_t, and I (and hopefully others, but obviously not too many) complained to them very loudly indeed.
Making it a size_t is completely broken, exactly because size_t very seldom is the same size as "int" on 64-bit architectures, for
example. And it _has_ to be the same size as "int" because that's what the BSD socket interface is. Anyway, the POSIX people
eventually got a clue, and created "socklen_t". They shouldn't have touched it in the first place, but once they did they felt it
had to have a named type for some unfathomable reason (probably somebody didn't like losing face over having done the original
stupid thing, so they silently just renamed their blunder)."
$ man connect
NOTE
The third argument of connect is in reality an int (and this is what BSD 4.* and libc4 and libc5 have). Some POSIX confusion
resulted in the present socklen_t, also used by glibc. See also accept(2).
$ man recvfrom
NOTE
The prototypes given above follow glibc2. The Single Unix Specification agrees, except that it has return values of type `ssize_t'
(while BSD 4.* and libc4 and libc5 all have `int'). The flags argument is `int' in BSD 4.*, but `unsigned int' in libc4 and libc5.
The len argument is `int' in BSD 4.*, but `size_t' in libc4 and libc5. The fromlen argument is `int *' in BSD 4.*, libc4 and
libc5. The present `socklen_t *' was invented by POSIX. See also accept(2). |
|