GNOME Bugzilla – Bug 611756
SO_KEEPALIVE value is actually a char on Windows, not BOOL
Last modified: 2010-03-12 09:05:03 UTC
I have used gsocket object under windows, if call g_socket_accept, there is a assert occured at Gsocket.c line:391 g_assert (optlen == sizeof bool_val); then, i have test it with winsock and the optional of SO_KEEPALIVE, like this: getsockopt (fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&bool_val, &optlen); the value of optlen is always 0, the assert certain occured. PS: My English is very poor, please forgive me...
sorry, i have a miss about my test in fact, under windows call like this : getsockopt (fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&bool_val, &optlen); the value of optlen is 1, but the sizeof bool is 4
Interesting. Could it be that the documentation is wrong and the SO_KEEPALIVE option value actually is a char in WinSock? You wouldn't happen to have some minimal complete test program that explicitly tests just this?
Yup, it certainly seems so. #include <glib.h> #include <winsock2.h> int main (int argc, char **argv) { WSADATA wsa_data; SOCKET s; BOOL b; int optlen, rc; g_assert (WSAStartup(0x0202, &wsa_data) == 0); s = socket (AF_INET, SOCK_STREAM, 0); g_assert (s != INVALID_SOCKET); g_print ("initial random value of b: %d\n", b); optlen = sizeof (b); rc = getsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (void*)&b, &optlen); g_assert (rc != SOCKET_ERROR); g_print ("SO_KEEPALIVE is %d bytes: %d (masked: %d)\n", optlen, b, (optlen == 4 ? b : (b & ((1 << (optlen*8))-1)))); b = 1; optlen = 4; g_print ("setting to %d\n", b); rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (void*)&b, optlen); g_assert (rc != SOCKET_ERROR); g_print ("setsockopt succeesed with optlen=%d\n", optlen); optlen = sizeof (b); rc = getsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (void*)&b, &optlen); g_assert (rc != SOCKET_ERROR); g_print ("SO_KEEPALIVE is %d bytes: %d (masked: %d)\n", optlen, b, (optlen == 4 ? b : (b & ((1 << (optlen*8))-1)))); b = 0; optlen = 4; g_print ("setting to %d\n", b); rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (void*)&b, optlen); g_assert (rc != SOCKET_ERROR); g_print ("setsockopt succeesed with optlen=%d\n", optlen); optlen = sizeof (b); rc = getsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (void*)&b, &optlen); g_assert (rc != SOCKET_ERROR); g_print ("SO_KEEPALIVE is %d bytes: %d (masked: %d)\n", optlen, b, (optlen == 4 ? b : (b & ((1 << (optlen*8))-1)))); b = 1; optlen = 1; g_print ("setting to %d\n", b); rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (void*)&b, optlen); g_assert (rc != SOCKET_ERROR); g_print ("setsockopt succeesed with optlen=%d too\n", optlen); optlen = sizeof (b); rc = getsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (void*)&b, &optlen); g_assert (rc != SOCKET_ERROR); g_print ("SO_KEEPALIVE is %d bytes: %d (masked: %d)\n", optlen, b, (optlen == 4 ? b : (b & ((1 << (optlen*8))-1)))); b = 0; optlen = 1; g_print ("setting to %d\n", b); rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (void*)&b, optlen); g_assert (rc != SOCKET_ERROR); g_print ("setsockopt succeesed with optlen=%d too\n", optlen); optlen = sizeof (b); rc = getsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (void*)&b, &optlen); g_assert (rc != SOCKET_ERROR); g_print ("SO_KEEPALIVE is %d bytes: %d (masked: %d)\n", optlen, b, (optlen == 4 ? b : (b & ((1 << (optlen*8))-1)))); return 0; }
of course MSDN explicitly says that it's a BOOL in multiple places... sigh. you could initialize bool_val to FALSE, and then remove the assert?
Created attachment 155276 [details] the errs screenshot
thanks for you two, and i am sorry for Tor Lillqvist that i have not given a completion simple test program. there's another question, i download the source of glib 2.22.4, and remove the assert, then i build glib with vs9, it sucessed. then i replaced my old glib's dlls and libs, run my program, there were some strange errors.the attachment is the screenshot. while, i actually call gtk_init(), gtk_init() should call g_type_init(), i call g_type_init() manually then, there's no errors, but also no effect about g_socket, for example: i attach a server socket for a source with G_IO_IN | G_IO_OUT, but the callback would not called, although there's a connection request with no errs...
Please don't start discussing different issues in this bug report. That will only make this bug report more confusing. What you describe in comment #6 are unrelated to the issue this bug is about.
okay... I think it is really a bug... i just hope you should fixed it next release, as well as you know, i could not continue my program now... at last, thanks for your work!
which "it" do you mean? You see now how confusing it is to talk about unrelated things in the same bug report? Please, do open a *separate* bug report for *separate* issues.
i'm sorry... "it" means the "g_assert (optlen == sizeof bool_val);", please forgive comment #6....
Fixed in glib-2-22 and master.
I am so sorry that I made some mistakes... This is my first time to communicate with foreigner, as well as you know, i am Chinese... And it is also my first time to report a bug with bugzilla to you... At last thanks for you that fixed the bug...