After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 611756 - SO_KEEPALIVE value is actually a char on Windows, not BOOL
SO_KEEPALIVE value is actually a char on Windows, not BOOL
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
2.22.x
Other Windows
: Normal critical
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2010-03-04 01:43 UTC by 张诚
Modified: 2010-03-12 09:05 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
the errs screenshot (867.76 KB, image/bmp)
2010-03-05 02:18 UTC, 张诚
Details

Description 张诚 2010-03-04 01:43:25 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...
Comment 1 张诚 2010-03-04 02:24:14 UTC
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
Comment 2 Tor Lillqvist 2010-03-04 09:45:07 UTC
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?
Comment 3 Tor Lillqvist 2010-03-04 10:01:33 UTC
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;
}
Comment 4 Dan Winship 2010-03-04 13:36:05 UTC
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?
Comment 5 张诚 2010-03-05 02:18:54 UTC
Created attachment 155276 [details]
the errs screenshot
Comment 6 张诚 2010-03-05 02:22:41 UTC
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...
Comment 7 Tor Lillqvist 2010-03-05 08:26:31 UTC
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.
Comment 8 张诚 2010-03-05 08:55:26 UTC
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!
Comment 9 Tor Lillqvist 2010-03-05 09:46:46 UTC
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.
Comment 10 张诚 2010-03-05 09:59:07 UTC
i'm sorry...

"it" means the "g_assert (optlen == sizeof bool_val);",

please forgive comment #6....
Comment 11 Tor Lillqvist 2010-03-12 08:47:45 UTC
Fixed in glib-2-22 and master.
Comment 12 张诚 2010-03-12 09:05:03 UTC
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...