@@ -302,7 +302,7 @@ static int alloc_empty_socket(rt_slist_t *l)
302
302
return idx ;
303
303
}
304
304
305
- static struct at_socket * alloc_socket_by_device (struct at_device * device )
305
+ static struct at_socket * alloc_socket_by_device (struct at_device * device , enum at_socket_type type )
306
306
{
307
307
static rt_mutex_t at_slock = RT_NULL ;
308
308
struct at_socket * sock = RT_NULL ;
@@ -323,14 +323,21 @@ static struct at_socket *alloc_socket_by_device(struct at_device *device)
323
323
rt_mutex_take (at_slock , RT_WAITING_FOREVER );
324
324
325
325
/* find an empty at socket entry */
326
- for (idx = 0 ; idx < device -> class -> socket_num && device -> sockets [idx ].magic ; idx ++ );
326
+ if (device -> class -> socket_ops -> at_socket != RT_NULL )
327
+ {
328
+ idx = device -> class -> socket_ops -> at_socket (device , type );
329
+ }
330
+ else
331
+ {
332
+ for (idx = 0 ; idx < device -> class -> socket_num && device -> sockets [idx ].magic ; idx ++ );
333
+ }
327
334
328
335
/* can't find an empty protocol family entry */
329
- if (idx = = device -> class -> socket_num )
336
+ if (idx < 0 || idx > = device -> class -> socket_num )
330
337
{
331
338
goto __err ;
332
339
}
333
-
340
+
334
341
sock = & (device -> sockets [idx ]);
335
342
/* the socket descriptor is the number of sockte lists */
336
343
sock -> socket = alloc_empty_socket (& (sock -> list ));
@@ -374,7 +381,7 @@ static struct at_socket *alloc_socket_by_device(struct at_device *device)
374
381
return RT_NULL ;
375
382
}
376
383
377
- static struct at_socket * alloc_socket (void )
384
+ static struct at_socket * alloc_socket (enum at_socket_type type )
378
385
{
379
386
extern struct netdev * netdev_default ;
380
387
struct netdev * netdev = RT_NULL ;
@@ -401,7 +408,7 @@ static struct at_socket *alloc_socket(void)
401
408
return RT_NULL ;
402
409
}
403
410
404
- return alloc_socket_by_device (device );
411
+ return alloc_socket_by_device (device , type );
405
412
}
406
413
407
414
static void at_recv_notice_cb (struct at_socket * sock , at_socket_evt_t event , const char * buff , size_t bfsz );
@@ -433,7 +440,7 @@ int at_socket(int domain, int type, int protocol)
433
440
}
434
441
435
442
/* allocate and initialize a new AT socket */
436
- sock = alloc_socket ();
443
+ sock = alloc_socket (socket_type );
437
444
if (sock == RT_NULL )
438
445
{
439
446
return -1 ;
@@ -615,7 +622,7 @@ int at_bind(int socket, const struct sockaddr *name, socklen_t namelen)
615
622
}
616
623
617
624
/* allocate new socket */
618
- new_sock = alloc_socket_by_device (new_device );
625
+ new_sock = alloc_socket_by_device (new_device , type );
619
626
if (new_sock == RT_NULL )
620
627
{
621
628
return -1 ;
0 commit comments