PDA

View Full Version : QT sockets on Windows 64 bit vs SOCKET



mikets
2nd June 2010, 13:25
Hi,

Sockets on Windows are defined as SOCKET type which is basically Windows handle which is 64 bit on Windows 64.

At the same time, I see that QT socket classes (QAbstractSocket, QSocketNotifier, etc.) work with socket descriptors as "int".

How does not it cause casting problem?

To me, it seems like something very basic, that I can't understand here.
Thanks,
Mike

mikets
3rd June 2010, 21:17
Anybody have an idea?

tbscope
3rd June 2010, 22:07
Yep:
http://bugreports.qt.nokia.com/browse/QTBUG-8275

wysota
4th June 2010, 01:03
I don't think they are going to change it (binary compatibility is a priority), so it's not really worth thinking about... Unless of course you expect to have more than 2^31 sockets in your application but I guess you'll run out of resources before you reach this count (especially that there are only 65535 ports for each of tcp and udp and other ("portless") protocols are not used that often).

mikets
4th June 2010, 08:58
While Unix / Linux indeed define sockets as sequential numbers, on Windows they are handle values, and thus nothing guarantees that a handle is still in 32 bit bounds, even if you have only one socket open. Or, may be there is a statement that handle values are still in 32-bit bounds?

wysota
4th June 2010, 09:03
I'm sure in Windows this is also sequential. Otherwise it would be hard to trace which ones are already taken. But of course that's Windows, so I might be wrong :)

mikets
4th June 2010, 10:37
You NEVER get sequential handles from Windows - I'm speaking about Win32 API, not CRT functions like _open

wysota
4th June 2010, 10:46
You NEVER get sequential handles from Windows - I'm speaking about Win32 API, not CRT functions like _open

How do you know they are not sequential across the whole system and that they are not reused after being freed?

squidge
4th June 2010, 14:26
Why don't we check?



#define NUM_HANDLES 1000

HANDLE h[NUM_HANDLES];
for (int i = 0; i < NUM_HANDLES; i ++)
{
h[i] = NULL;
h[i] = CreateFile("C:\\Temp.log",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,F ILE_ATTRIBUTE_NORMAL,NULL);
}

for (int i = 0; i < NUM_HANDLES; i ++)
printf("%08X, ", h[i]);


gives:

0000072C, 00000728, 00000724, 00000720, 0000071C, 00000718, 00000714, 00000710, 0000070C, 00000708, 00000704, 00000700, 000006FC, 000006F8, 000006F4, 000006F0, 000006EC, 000006E8, 000006E4, 000006E0, 000006DC, 000006D8, 000006D4, 000006D0, 000006CC, 000006C8, 000006C4, 000006C0, 000006BC, 000006B8, 000006B4, 000006B0, 000006AC, 000006A8, 000006A4, 000006A0, 0000069C, 00000698, 00000694, 00000690, 0000068C, 00000688, 00000684, 00000680, 0000067C, 00000678, 00000674, 00000670, 0000066C, 00000668, 00000664, 00000660, 0000065C, 00000658, 00000654, 00000650, 0000064C, 00000648, 00000644, 00000640, 0000063C, 00000638, 00000634, 00000630, 0000062C, 00000628, 00000624, 00000620, 0000061C, 00000618, 00000614, 00000610, 0000060C, 00000608, 00000604, 00000600, 000005FC, 000005F8, 000005F4, 000005F0, 000005EC, 000005E8, 000005E4, 000005E0, 000005DC, 000005D8, 000005D4, 000005D0, 000005CC, 000005C8, 000005C4, 000005C0, 000005BC, 000005B8, 000005B4, 000005B0, 000005AC, 000005A8, 000005A4, 000005A0, 0000059C, 00000598, 00000594, 00000590, 0000058C, 00000588, 00000584, 00000580, 0000057C, 00000578, 00000574, 00000570, 0000056C, 00000568, 00000564, 00000560, 0000055C, 00000558, 00000554, 00000550, 0000054C, 00000548, 00000544, 00000540, 0000053C, 00000538, 00000534, 00000530, 0000052C, 00000528, 00000524, 00000520, 0000051C, 00000518, 00000514, 00000510, 0000050C, 00000508, 00000504, 00000500, 000004FC, 000004F8, 000004F4, 000004F0, 000004EC, 000004E8, 000004E4, 000004E0, 000004DC, 000004D8, 000004D4, 000004D0, 000004CC, 000004C8, 000004C4, 000004C0, 000004BC, 000004B8, 000004B4, 000004B0, 000004AC, 000004A8, 000004A4, 000004A0, 0000049C, 00000498, 00000494, 00000490, 0000048C, 00000488, 00000484, 00000480, 0000047C, 00000474, 00000470, 0000046C, 00000468, 00000464, 00000460, 0000045C, 00000458, 00000454, 00000450, 0000044C, 00000448, 00000444, 00000440, 0000043C, 00000438, 00000434, 00000430, 0000042C, 00000428, 00000424, 00000420, 0000041C, 00000418, 00000410, 0000040C, 00000408, 00000404, 00000400, 000003FC, 000003F8, 000003F4, 000003F0, 000003EC, 000003E8, 000003E4, 000003E0, 000003DC, 000003D8, 000003D4, 000003D0, 000003CC, 000003C8, 000003C4, 000003C0, 000003BC, 000003B8, 000003B4, 000003B0, 000003AC, 000003A8, 000003A4, 000003A0, 0000039C, 00000398, 00000394, 00000390, 0000038C, 00000388, 00000384, 00000380, 0000037C, 00000378, 00000374, 00000370, 0000036C, 00000368, 00000364, 00000360, 0000035C, 00000358, 00000354, 00000350, 0000034C, 00000348, 00000344, 00000340, 0000033C, 00000338, 00000334, 00000330, 0000032C, 00000328, 00000324, 00000320, 0000031C, 00000318, 00000314, 00000310, 0000030C, 00000308, 00000304, 00000300, 000002FC, 000002F8, 000002F4, 000002F0, 000002EC, 000002E8, 000002E4, 000002E0, 000002DC, 000002D8, 000002D4, 000002D0, 000002CC, 000002C8, 000002C4, 000002C0, 000002BC, 000002B8, 000002B4, 000002B0, 000002AC, 000002A8, 000002A4, 000002A0, 0000029C, 00000298, 00000294, 00000290, 0000028C, 00000288, 00000284, 00000280, 0000027C, 00000278, 00000274, 00000270, 0000026C, 00000268, 00000264, 00000260, 0000025C, 00000258, 00000254, 00000250, 0000024C, 00000248, 00000244, 00000240, 0000023C, 00000238, 00000234, 00000230, 0000022C, 00000228, 00000224, 00000220, 0000021C, 00000218, 00000214, 00000210, 0000020C, 00000208, 00000204, 00000200, 000001FC, 000001F8, 000001F4, 000001F0, 000001EC, 000001E8, 000001E4, 000001E0, 000001DC, 000001D8, 000001D4, 000001D0, 000001CC, 000001C8, 000001C4, 000001C0, 000001BC, 000001B8, 000001B4, 000001B0, 000001AC, 000001A8, 000001A4, 000001A0, 0000019C, 00000198, 00000194, 00000190, 0000018C, 00000188, 00000184, 00000180, 0000017C, 00000178, 00000174, 00000170, 0000016C, 00000168, 00000164, 00000160, 0000015C, 00000158, 00000154, 00000150, 0000014C, 00000148, 00000144, 00000140, 0000013C, 00000138, 00000134, 00000130, 0000012C, 00000128, 00000124, 00000120, 0000011C, 00000118, 00000114, 00000110, 0000010C, 00000108, 00000104, 00000100, 000000FC, 000000F8, 000000F4, 000000F0, 000000EC, 000000E8, 000000E4, 000000E0, 000000DC, 000000D8, 000000D4, 000000D0, 000000CC, 000000C8, 000000C4, 000000C0, 000000BC, 000000B8, 000000B4, 000000B0, 000000AC, 000000A8, 000000A4, 000000A0, 0000009C, 00000098, 00000094, 00000090, 0000008C, 00000088, 00000084, 00000080, 0000007C, 00000078, 00000074, 00000070, 0000006C, 00000068, 00000064, 00000060, 0000005C, 00000058, 00000054, 00000050, 0000004C, 00000048, 00000044, 00000040, 0000003C, 00000038, 00000034, 00000030, 0000002C, 00000028, 00000024, 00000020, 0000001C, 00000018, 00000014, 00000010, 0000000C, 00000008, 00000004, 00000804, 00000808, 0000080C, 00000810, 00000814, 00000818, 0000081C, 00000820, 00000824, 00000828, 0000082C, 00000830, 00000834, 00000838, 0000083C, 00000840, 00000844, 00000848, 0000084C, 00000850, 00000854, 00000858, 0000085C, 00000860, 00000864, 00000868, 0000086C, 00000870, 00000874, 00000878, 0000087C, 00000880, 00000884, 00000888, 0000088C, 00000890, 00000894, 00000898, 0000089C, 000008A0, 000008A4, 000008A8, 000008AC, 000008B0, 000008B4, 000008B8, 000008BC, 000008C0, 000008C4, 000008C8, 000008CC, 000008D0, 000008D4, 000008D8, 000008DC, 000008E0, 000008E4, 000008E8, 000008EC, 000008F0, 000008F4, 000008F8, 000008FC, 00000900, 00000904, 00000908, 0000090C, 00000910, 00000914, 00000918, 0000091C, 00000920, 00000924, 00000928, 0000092C, 00000930, 00000934, 00000938, 0000093C, 00000940, 00000944, 00000948, 0000094C, 00000950, 00000954, 00000958, 0000095C, 00000960, 00000964, 00000968, 0000096C, 00000970, 00000974, 00000978, 0000097C, 00000980, 00000984, 00000988, 0000098C, 00000990, 00000994, 00000998, 0000099C, 000009A0, 000009A4, 000009A8, 000009AC, 000009B0, 000009B4, 000009B8, 000009BC, 000009C0, 000009C4, 000009C8, 000009CC, 000009D0, 000009D4, 000009D8, 000009DC, 000009E0, 000009E4, 000009E8, 000009EC, 000009F0, 000009F4, 000009F8, 000009FC, 00000A00, 00000A04, 00000A08, 00000A0C, 00000A10, 00000A14, 00000A18, 00000A1C, 00000A20, 00000A24, 00000A28, 00000A2C, 00000A30, 00000A34, 00000A38, 00000A3C, 00000A40, 00000A44, 00000A48, 00000A4C, 00000A50, 00000A54, 00000A58, 00000A5C, 00000A60, 00000A64, 00000A68, 00000A6C, 00000A70, 00000A74, 00000A78, 00000A7C, 00000A80, 00000A84, 00000A88, 00000A8C, 00000A90, 00000A94, 00000A98, 00000A9C, 00000AA0, 00000AA4, 00000AA8, 00000AAC, 00000AB0, 00000AB4, 00000AB8, 00000ABC, 00000AC0, 00000AC4, 00000AC8, 00000ACC, 00000AD0, 00000AD4, 00000AD8, 00000ADC, 00000AE0, 00000AE4, 00000AE8, 00000AEC, 00000AF0, 00000AF4, 00000AF8, 00000AFC, 00000B00, 00000B04, 00000B08, 00000B0C, 00000B10, 00000B14, 00000B18, 00000B1C, 00000B20, 00000B24, 00000B28, 00000B2C, 00000B30, 00000B34, 00000B38, 00000B3C, 00000B40, 00000B44, 00000B48, 00000B4C, 00000B50, 00000B54, 00000B58, 00000B5C, 00000B60, 00000B64, 00000B68, 00000B6C, 00000B70, 00000B74, 00000B78, 00000B7C, 00000B80, 00000B84, 00000B88, 00000B8C, 00000B90, 00000B94, 00000B98, 00000B9C, 00000BA0, 00000BA4, 00000BA8, 00000BAC, 00000BB0, 00000BB4, 00000BB8, 00000BBC, 00000BC0, 00000BC4, 00000BC8, 00000BCC, 00000BD0, 00000BD4, 00000BD8, 00000BDC, 00000BE0, 00000BE4, 00000BE8, 00000BEC, 00000BF0, 00000BF4, 00000BF8, 00000BFC, 00000C00, 00000C04, 00000C08, 00000C0C, 00000C10, 00000C14, 00000C18, 00000C1C, 00000C20, 00000C24, 00000C28, 00000C2C, 00000C30, 00000C34, 00000C38, 00000C3C, 00000C40, 00000C44, 00000C48, 00000C4C, 00000C50, 00000C54, 00000C58, 00000C5C, 00000C60, 00000C64, 00000C68, 00000C6C, 00000C70, 00000C74, 00000C78, 00000C7C, 00000C80, 00000C84, 00000C88, 00000C8C, 00000C90, 00000C94, 00000C98, 00000C9C, 00000CA0, 00000CA4, 00000CA8, 00000CAC, 00000CB0, 00000CB4, 00000CB8, 00000CBC, 00000CC0, 00000CC4, 00000CC8, 00000CCC, 00000CD0, 00000CD4, 00000CD8, 00000CDC, 00000CE0, 00000CE4, 00000CE8, 00000CEC, 00000CF0, 00000CF4, 00000CF8, 00000CFC, 00000D00, 00000D04, 00000D08, 00000D0C, 00000D10, 00000D14, 00000D18, 00000D1C, 00000D20, 00000D24, 00000D28, 00000D2C, 00000D30, 00000D34, 00000D38, 00000D3C, 00000D40, 00000D44, 00000D48, 00000D4C, 00000D50, 00000D54, 00000D58, 00000D5C, 00000D60, 00000D64, 00000D68, 00000D6C, 00000D70, 00000D74, 00000D78, 00000D7C, 00000D80, 00000D84, 00000D88, 00000D8C, 00000D90, 00000D94, 00000D98, 00000D9C, 00000DA0, 00000DA4, 00000DA8, 00000DAC, 00000DB0, 00000DB4, 00000DB8, 00000DBC, 00000DC0, 00000DC4, 00000DC8, 00000DCC, 00000DD0, 00000DD4, 00000DD8, 00000DDC, 00000DE0, 00000DE4, 00000DE8, 00000DEC, 00000DF0, 00000DF4, 00000DF8, 00000DFC, 00000E00, 00000E04, 00000E08, 00000E0C, 00000E10, 00000E14, 00000E18, 00000E1C, 00000E20, 00000E24, 00000E28, 00000E2C, 00000E30, 00000E34, 00000E38, 00000E3C, 00000E40, 00000E44, 00000E48, 00000E4C, 00000E50, 00000E54, 00000E58, 00000E5C, 00000E60, 00000E64, 00000E68, 00000E6C, 00000E70, 00000E74, 00000E78, 00000E7C, 00000E80, 00000E84, 00000E88, 00000E8C, 00000E90, 00000E94, 00000E98, 00000E9C, 00000EA0, 00000EA4, 00000EA8, 00000EAC, 00000EB0, 00000EB4, 00000EB8, 00000EBC, 00000EC0, 00000EC4, 00000EC8, 00000ECC, 00000ED0, 00000ED4, 00000ED8, 00000EDC, 00000EE0, 00000EE4, 00000EE8, 00000EEC, 00000EF0, 00000EF4, 00000EF8, 00000EFC, 00000F00, 00000F04, 00000F08, 00000F0C, 00000F10, 00000F14, 00000F18, 00000F1C, 00000F20, 00000F24, 00000F28, 00000F2C, 00000F30, 00000F34, 00000F38, 00000F3C, 00000F40, 00000F44, 00000F48, 00000F4C, 00000F50, 00000F54, 00000F58, 00000F5C, 00000F60,

Not completely sequential, but close enough!

[Some output was removed to be under the 10K limit]

wysota
4th June 2010, 15:49
There is obviously a pattern here :)