• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/bt


Commit MetaInfo

Revision223015ecd785a86cc97af3bedbcb311b3ec5d9be (tree)
Zeit2017-04-05 19:55:42
AutorMingbo Zhang <mingboz@code...>
CommiterGerrit - the friendly Code Review server

Log Message

uipc: retry to create srv chan if EADDRINUSE error

In very rare cases, socket cannot be closed in time.
Then we will fail to create the same socket immediately.
So need to retry after EADDRINUSE error happens

Change-Id: I1e54ded102d38cd42b3df40d405205a79b08928b
CRs-Fixed: 2029248

Ändern Zusammenfassung

Diff

--- a/udrv/ulinux/uipc.c
+++ b/udrv/ulinux/uipc.c
@@ -67,6 +67,9 @@
6767
6868 #define UIPC_FLUSH_BUFFER_SIZE 1024
6969
70+#define CHAN_CREATE_WAIT_TIME_MS 30
71+#define CHAN_CREATE_RETRY_COUNT 10
72+
7073 /*****************************************************************************
7174 ** Local type definitions
7275 ******************************************************************************/
@@ -143,6 +146,7 @@ const char* dump_uipc_event(tUIPC_EVENT event)
143146
144147 static inline int create_server_socket(const char* name)
145148 {
149+ int ret;
146150 int s = socket(AF_LOCAL, SOCK_STREAM, 0);
147151 if (s < 0)
148152 return -1;
@@ -151,9 +155,10 @@ static inline int create_server_socket(const char* name)
151155
152156 if(osi_socket_local_server_bind(s, name, ANDROID_SOCKET_NAMESPACE_ABSTRACT) < 0)
153157 {
158+ ret = (errno == EADDRINUSE ? -EADDRINUSE : -1);
154159 BTIF_TRACE_EVENT("socket failed to create (%s)", strerror(errno));
155160 close(s);
156- return -1;
161+ return ret;
157162 }
158163
159164 if(listen(s, 5) < 0)
@@ -350,6 +355,7 @@ static inline void uipc_wakeup_locked(void)
350355 static int uipc_setup_server_locked(tUIPC_CH_ID ch_id, char *name, tUIPC_RCV_CBACK *cback)
351356 {
352357 int fd;
358+ int i;
353359
354360 BTIF_TRACE_EVENT("SETUP CHANNEL SERVER %d", ch_id);
355361
@@ -358,7 +364,19 @@ static int uipc_setup_server_locked(tUIPC_CH_ID ch_id, char *name, tUIPC_RCV_CBA
358364
359365 UIPC_LOCK();
360366
361- fd = create_server_socket(name);
367+ for (i = 0; i < CHAN_CREATE_RETRY_COUNT; i++)
368+ {
369+ fd = create_server_socket(name);
370+ if (fd == -EADDRINUSE)
371+ {
372+ BTIF_TRACE_ERROR("Address already in use, retry: %d", i);
373+ usleep(CHAN_CREATE_WAIT_TIME_MS * 1000);
374+ }
375+ else
376+ {
377+ break;
378+ }
379+ }
362380
363381 if (fd < 0)
364382 {