~vcs-imports/gnome-media/main

« back to all changes in this revision

Viewing changes to cddb-slave2/gnet-private.c

  • Committer: thomasvs
  • Date: 2004-05-10 08:52:25 UTC
  • Revision ID: vcs-imports@canonical.com-20040510085225-zb6tqc12yi1h08gd
remove unneccesary whitespace

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 * Library General Public License for more details.
14
14
 *
15
15
 * You should have received a copy of the GNU Library General Public
16
 
 * License along with this library; if not, write to the 
 
16
 * License along with this library; if not, write to the
17
17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
18
 * Boston, MA  02111-1307, USA.
19
19
 */
29
29
 *  Create an internet address from a sockaddr struct.  WARNING: This
30
30
 *  may go away or be hidden in a future version.
31
31
 *
32
 
 *  Returns: a new InetAddr, or NULL if there was a failure.  
 
32
 *  Returns: a new InetAddr, or NULL if there was a failure.
33
33
 *
34
34
 **/
35
 
GInetAddr* 
 
35
GInetAddr*
36
36
gnet_private_inetaddr_sockaddr_new(const struct sockaddr sa)
37
37
{
38
38
  GInetAddr* ia = g_new0(GInetAddr, 1);
53
53
 *
54
54
 *  Returns: the sockaddr struct
55
55
 **/
56
 
struct sockaddr 
 
56
struct sockaddr
57
57
gnet_private_inetaddr_get_sockaddr(const GInetAddr* ia)
58
58
{
59
59
  g_assert(ia != NULL);
71
71
 *  gnet_udp_socket_get_MTU:
72
72
 *  @us: GUdpSocket to get MTU from.
73
73
 *
74
 
 *  Get the MTU for outgoing packets.  
 
74
 *  Get the MTU for outgoing packets.
75
75
 *
76
76
 *  Returns: MTU; -1 if unknown.
77
77
 *
83
83
 
84
84
  /* FIX: Not everyone has ethernet, right? */
85
85
  strncpy (ifr.ifr_name, "eth0", sizeof (ifr.ifr_name));
86
 
  if (!ioctl(us->sockfd, SIOCGIFMTU, &ifr)) 
 
86
  if (!ioctl(us->sockfd, SIOCGIFMTU, &ifr))
87
87
    return ifr.ifr_mtu;
88
88
 
89
89
  return -1;
94
94
 
95
95
 
96
96
 
97
 
/* 
 
97
/*
98
98
 
99
99
   Below is the Windows specific code and a general idea of how
100
100
   things were implemented.
136
136
         code were fixed so only a few gnet functions still use this method.
137
137
 
138
138
   I believe I have taken care of the multi-threaded issues by using
139
 
   mutexes.  
 
139
   mutexes.
140
140
 
141
141
*/
142
142
 
143
143
#ifdef GNET_WIN32
144
144
 
145
145
WNDCLASSEX gnetWndClass;
146
 
HWND  gnet_hWnd; 
 
146
HWND  gnet_hWnd;
147
147
guint gnet_io_watch_ID;
148
148
GIOChannel *gnet_iochannel;
149
 
        
 
149
 
150
150
GHashTable *gnet_hash;
151
 
HANDLE gnet_Mutex; 
 
151
HANDLE gnet_Mutex;
152
152
HANDLE gnet_hostent_Mutex;
153
153
 
154
154
 
155
 
int 
 
155
int
156
156
gnet_MainCallBack(GIOChannel *iochannel, GIOCondition condition, void *nodata)
157
157
{
158
158
  MSG msg;
164
164
  int i;
165
165
 
166
166
  /*Take the msg off the message queue */
167
 
  i = PeekMessage (&msg, gnet_hWnd, 0, 0, PM_REMOVE); 
 
167
  i = PeekMessage (&msg, gnet_hWnd, 0, 0, PM_REMOVE);
168
168
  if (!i)
169
169
    return 1; /* you have a buggy version of glib that is calling this func when it shouldn't*/
170
170
 
171
 
  switch (msg.message) 
 
171
  switch (msg.message)
172
172
    {
173
173
    case IA_NEW_MSG:
174
174
      {
176
176
        data = g_hash_table_lookup(gnet_hash, (gpointer)msg.wParam);
177
177
        g_hash_table_remove(gnet_hash, (gpointer)msg.wParam);
178
178
        ReleaseMutex(gnet_Mutex);
179
 
                
 
179
 
180
180
        IAstate = (GInetAddrAsyncState*) data;
181
181
        IAstate->errorcode = WSAGETASYNCERROR(msg.lParam); /* NULL if OK */
182
182
 
194
194
 
195
195
        IARstate = (GInetAddrReverseAsyncState*) data;
196
196
        IARstate->errorcode = WSAGETASYNCERROR(msg.lParam); /* NULL if OK */
197
 
                        
 
197
 
198
198
        /* Now call the callback function */
199
199
        gnet_inetaddr_get_name_async_cb(NULL, G_IO_IN, (gpointer)IARstate);
200
200
        break;
210
210
            UINT uMsg,        /* message identifier */
211
211
            WPARAM wParam,    /* first message parameter */
212
212
            LPARAM lParam)    /* second message parameter */
213
 
 
213
{
214
214
 
215
 
    switch (uMsg) 
216
 
    { 
217
 
        case WM_CREATE: 
 
215
    switch (uMsg)
 
216
    {
 
217
        case WM_CREATE:
218
218
            /* Initialize the window. */
219
 
            return 0; 
220
 
 
221
 
        case WM_PAINT: 
222
 
            /* Paint the window's client area. */ 
223
 
            return 0; 
224
 
 
225
 
        case WM_SIZE: 
226
 
            /* Set the size and position of the window. */ 
227
 
            return 0; 
228
 
 
229
 
        case WM_DESTROY: 
 
219
            return 0;
 
220
 
 
221
        case WM_PAINT:
 
222
            /* Paint the window's client area. */
 
223
            return 0;
 
224
 
 
225
        case WM_SIZE:
 
226
            /* Set the size and position of the window. */
 
227
            return 0;
 
228
 
 
229
        case WM_DESTROY:
230
230
            /* Clean up window-specific data objects. */
231
 
            return 0; 
232
 
 
233
 
        /* 
234
 
          Process other messages. 
235
 
        */ 
236
 
 
237
 
        default: 
238
 
            return DefWindowProc(hwnd, uMsg, wParam, lParam); 
239
 
    } 
240
 
    return 0; 
241
 
242
 
 
243
 
 
244
 
BOOL WINAPI 
 
231
            return 0;
 
232
 
 
233
        /*
 
234
          Process other messages.
 
235
        */
 
236
 
 
237
        default:
 
238
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
 
239
    }
 
240
    return 0;
 
241
}
 
242
 
 
243
 
 
244
BOOL WINAPI
245
245
DllMain(HINSTANCE hinstDLL,  /* handle to DLL module */
246
246
        DWORD fdwReason,     /* reason for calling functionm */
247
247
        LPVOID lpvReserved   /* reserved */)
248
248
{
249
249
 
250
 
  switch(fdwReason) 
 
250
  switch(fdwReason)
251
251
    {
252
252
    case DLL_PROCESS_ATTACH:
253
253
      /* The DLL is being mapped into process's address space */
256
256
        WORD wVersionRequested;
257
257
        WSADATA wsaData;
258
258
        int err;
259
 
 
 
259
 
260
260
        wVersionRequested = MAKEWORD( 2, 0 );
261
 
 
 
261
 
262
262
        err = WSAStartup( wVersionRequested, &wsaData );
263
 
        if ( err != 0 ) 
 
263
        if ( err != 0 )
264
264
          {
265
265
                                /* Tell the user that we could not find a usable */
266
266
                                /* WinSock DLL.                                  */
267
267
            return FALSE;
268
268
          }
269
 
 
 
269
 
270
270
        /* Confirm that the WinSock DLL supports 2.0.*/
271
271
        /* Note that if the DLL supports versions greater    */
272
272
        /* than 2.0 in addition to 2.0, it will still return */
273
273
        /* 2.0 in wVersion since that is the version we      */
274
274
        /* requested.                                        */
275
 
 
 
275
 
276
276
        if ( LOBYTE( wsaData.wVersion ) != 2 ||
277
277
             HIBYTE( wsaData.wVersion ) != 0 ) {
278
278
          /* Tell the user that we could not find a usable */
279
279
          /* WinSock DLL.                                  */
280
280
          WSACleanup();
281
 
          return FALSE; 
 
281
          return FALSE;
282
282
        }
283
 
 
 
283
 
284
284
        /* The WinSock DLL is acceptable. Proceed. */
285
285
 
286
286
        /* Setup and register a windows class that we use for our GIOchannel */
287
 
        gnetWndClass.cbSize = sizeof(WNDCLASSEX); 
288
 
        gnetWndClass.style = CS_SAVEBITS; /* doesn't matter, need something? */ 
289
 
        gnetWndClass.lpfnWndProc = (WNDPROC) GnetWndProc; 
290
 
        gnetWndClass.cbClsExtra = 0; 
291
 
        gnetWndClass.cbWndExtra = 0; 
292
 
        gnetWndClass.hInstance = hinstDLL; 
293
 
        gnetWndClass.hIcon = NULL; 
294
 
        gnetWndClass.hCursor = NULL; 
295
 
        gnetWndClass.hbrBackground = NULL; 
296
 
        gnetWndClass.lpszMenuName = NULL; 
297
 
        gnetWndClass.lpszClassName = "Gnet"; 
298
 
        gnetWndClass.hIconSm = NULL; 
 
287
        gnetWndClass.cbSize = sizeof(WNDCLASSEX);
 
288
        gnetWndClass.style = CS_SAVEBITS; /* doesn't matter, need something? */
 
289
        gnetWndClass.lpfnWndProc = (WNDPROC) GnetWndProc;
 
290
        gnetWndClass.cbClsExtra = 0;
 
291
        gnetWndClass.cbWndExtra = 0;
 
292
        gnetWndClass.hInstance = hinstDLL;
 
293
        gnetWndClass.hIcon = NULL;
 
294
        gnetWndClass.hCursor = NULL;
 
295
        gnetWndClass.hbrBackground = NULL;
 
296
        gnetWndClass.lpszMenuName = NULL;
 
297
        gnetWndClass.lpszClassName = "Gnet";
 
298
        gnetWndClass.hIconSm = NULL;
299
299
 
300
300
        if (!RegisterClassEx(&gnetWndClass))
301
301
          {
302
 
            return FALSE;       
 
302
            return FALSE;
303
303
          }
304
304
 
305
305
        gnet_hWnd  = CreateWindowEx
306
306
          (
307
307
           0,
308
 
           "Gnet", 
 
308
           "Gnet",
309
309
           "none",
310
 
           WS_OVERLAPPEDWINDOW, 
311
 
           CW_USEDEFAULT, 
312
 
           CW_USEDEFAULT, 
313
 
           CW_USEDEFAULT, 
314
 
           CW_USEDEFAULT, 
315
 
           (HWND) NULL, 
316
 
           (HMENU) NULL, 
317
 
           hinstDLL, 
318
 
           (LPVOID) NULL);  
 
310
           WS_OVERLAPPEDWINDOW,
 
311
           CW_USEDEFAULT,
 
312
           CW_USEDEFAULT,
 
313
           CW_USEDEFAULT,
 
314
           CW_USEDEFAULT,
 
315
           (HWND) NULL,
 
316
           (HMENU) NULL,
 
317
           hinstDLL,
 
318
           (LPVOID) NULL);
319
319
 
320
 
        if (!gnet_hWnd) 
 
320
        if (!gnet_hWnd)
321
321
          {
322
322
            return FALSE;
323
323
          }
327
327
        /* Add a watch */
328
328
        gnet_io_watch_ID = g_io_add_watch(gnet_iochannel,
329
329
                                          (GIOCondition)(G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL),
330
 
                                          gnet_MainCallBack, 
 
330
                                          gnet_MainCallBack,
331
331
                                          NULL);
332
332
 
333
 
        gnet_hash = g_hash_table_new(NULL, NULL);       
 
333
        gnet_hash = g_hash_table_new(NULL, NULL);
334
334
 
335
 
        gnet_Mutex = CreateMutex( 
 
335
        gnet_Mutex = CreateMutex(
336
336
                                 NULL,                       /* no security attributes */
337
337
                                 FALSE,                      /* initially not owned */
338
338
                                 "gnet_Mutex");  /* name of mutex */
339
339
 
340
 
        if (gnet_Mutex == NULL) 
 
340
        if (gnet_Mutex == NULL)
341
341
          {
342
342
            return FALSE;
343
343
          }
344
344
 
345
 
        gnet_hostent_Mutex = CreateMutex( 
 
345
        gnet_hostent_Mutex = CreateMutex(
346
346
                                         NULL,                       /* no security attributes */
347
347
                                         FALSE,                      /* initially not owned */
348
348
                                         "gnet_hostent_Mutex");  /* name of mutex */
349
349
 
350
 
        if (gnet_hostent_Mutex == NULL) 
 
350
        if (gnet_hostent_Mutex == NULL)
351
351
          {
352
352
            return FALSE;
353
353
          }
361
361
      }
362
362
    case DLL_THREAD_DETACH:
363
363
      /* Thread exits with  cleanup */
364
 
      { 
 
364
      {
365
365
        /*Nothing needs to be done. */
366
366
        break;
367
367
      }
381
381
 
382
382
  return TRUE;
383
383
}
384
 
 
 
384
 
385
385
#endif