system/corennnnn
Revision | 1b154930b2c2634dce9c04d5d5cec7acb229ccb0 (tree) |
---|---|
Zeit | 2009-05-19 18:52:19 |
Autor | Android (Google) Code Review <android-gerrit@goog...> |
Commiter | Android (Google) Code Review |
Merge change 1867 into donut
* changes:
@@ -87,7 +87,7 @@ static void fdevent_init() | ||
87 | 87 | { |
88 | 88 | /* XXX: what's a good size for the passed in hint? */ |
89 | 89 | epoll_fd = epoll_create(256); |
90 | - | |
90 | + | |
91 | 91 | if(epoll_fd < 0) { |
92 | 92 | perror("epoll_create() failed"); |
93 | 93 | exit(1); |
@@ -105,7 +105,7 @@ static void fdevent_connect(fdevent *fde) | ||
105 | 105 | ev.events = 0; |
106 | 106 | ev.data.ptr = fde; |
107 | 107 | |
108 | -#if 0 | |
108 | +#if 0 | |
109 | 109 | if(epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fde->fd, &ev)) { |
110 | 110 | perror("epoll_ctl() failed\n"); |
111 | 111 | exit(1); |
@@ -116,7 +116,7 @@ static void fdevent_connect(fdevent *fde) | ||
116 | 116 | static void fdevent_disconnect(fdevent *fde) |
117 | 117 | { |
118 | 118 | struct epoll_event ev; |
119 | - | |
119 | + | |
120 | 120 | memset(&ev, 0, sizeof(ev)); |
121 | 121 | ev.events = 0; |
122 | 122 | ev.data.ptr = fde; |
@@ -133,9 +133,9 @@ static void fdevent_update(fdevent *fde, unsigned events) | ||
133 | 133 | { |
134 | 134 | struct epoll_event ev; |
135 | 135 | int active; |
136 | - | |
136 | + | |
137 | 137 | active = (fde->state & FDE_EVENTMASK) != 0; |
138 | - | |
138 | + | |
139 | 139 | memset(&ev, 0, sizeof(ev)); |
140 | 140 | ev.events = 0; |
141 | 141 | ev.data.ptr = fde; |
@@ -241,7 +241,7 @@ static void fdevent_connect(fdevent *fde) | ||
241 | 241 | static void fdevent_disconnect(fdevent *fde) |
242 | 242 | { |
243 | 243 | int i, n; |
244 | - | |
244 | + | |
245 | 245 | FD_CLR(fde->fd, &read_fds); |
246 | 246 | FD_CLR(fde->fd, &write_fds); |
247 | 247 | FD_CLR(fde->fd, &error_fds); |
@@ -283,9 +283,9 @@ static void fdevent_process() | ||
283 | 283 | memcpy(&rfd, &read_fds, sizeof(fd_set)); |
284 | 284 | memcpy(&wfd, &write_fds, sizeof(fd_set)); |
285 | 285 | memcpy(&efd, &error_fds, sizeof(fd_set)); |
286 | - | |
286 | + | |
287 | 287 | n = select(select_n, &rfd, &wfd, &efd, 0); |
288 | - | |
288 | + | |
289 | 289 | if(n < 0) { |
290 | 290 | if(errno == EINTR) return; |
291 | 291 | perror("select"); |
@@ -300,12 +300,12 @@ static void fdevent_process() | ||
300 | 300 | |
301 | 301 | if(events) { |
302 | 302 | n--; |
303 | - | |
303 | + | |
304 | 304 | fde = fd_table[i]; |
305 | 305 | if(fde == 0) FATAL("missing fde for fd %d\n", i); |
306 | 306 | |
307 | 307 | fde->events |= events; |
308 | - | |
308 | + | |
309 | 309 | if(fde->state & FDE_PENDING) continue; |
310 | 310 | fde->state |= FDE_PENDING; |
311 | 311 | fdevent_plist_enqueue(fde); |
@@ -320,7 +320,7 @@ static void fdevent_register(fdevent *fde) | ||
320 | 320 | if(fde->fd < 0) { |
321 | 321 | FATAL("bogus negative fd (%d)\n", fde->fd); |
322 | 322 | } |
323 | - | |
323 | + | |
324 | 324 | if(fde->fd >= fd_table_max) { |
325 | 325 | int oldmax = fd_table_max; |
326 | 326 | if(fde->fd > 32000) { |
@@ -383,9 +383,9 @@ static fdevent *fdevent_plist_dequeue(void) | ||
383 | 383 | { |
384 | 384 | fdevent *list = &list_pending; |
385 | 385 | fdevent *node = list->next; |
386 | - | |
386 | + | |
387 | 387 | if(node == list) return 0; |
388 | - | |
388 | + | |
389 | 389 | list->next = node->next; |
390 | 390 | list->next->prev = list; |
391 | 391 | node->next = 0; |
@@ -449,9 +449,9 @@ void fdevent_remove(fdevent *fde) | ||
449 | 449 | void fdevent_set(fdevent *fde, unsigned events) |
450 | 450 | { |
451 | 451 | events &= FDE_EVENTMASK; |
452 | - | |
452 | + | |
453 | 453 | if((fde->state & FDE_EVENTMASK) == events) return; |
454 | - | |
454 | + | |
455 | 455 | if(fde->state & FDE_ACTIVE) { |
456 | 456 | fdevent_update(fde, events); |
457 | 457 | dump_fde(fde, "update"); |
@@ -487,13 +487,13 @@ void fdevent_del(fdevent *fde, unsigned events) | ||
487 | 487 | void fdevent_loop() |
488 | 488 | { |
489 | 489 | fdevent *fde; |
490 | - | |
490 | + | |
491 | 491 | for(;;) { |
492 | 492 | #if DEBUG |
493 | 493 | fprintf(stderr,"--- ---- waiting for events\n"); |
494 | 494 | #endif |
495 | 495 | fdevent_process(); |
496 | - | |
496 | + | |
497 | 497 | while((fde = fdevent_plist_dequeue())) { |
498 | 498 | unsigned events = fde->events; |
499 | 499 | fde->events = 0; |
@@ -17,10 +17,13 @@ | ||
17 | 17 | #ifndef __FDEVENT_H |
18 | 18 | #define __FDEVENT_H |
19 | 19 | |
20 | +#include <stdint.h> /* for int64_t */ | |
21 | + | |
20 | 22 | /* events that may be observed */ |
21 | 23 | #define FDE_READ 0x0001 |
22 | 24 | #define FDE_WRITE 0x0002 |
23 | 25 | #define FDE_ERROR 0x0004 |
26 | +#define FDE_TIMEOUT 0x0008 | |
24 | 27 | |
25 | 28 | /* features that may be set (via the events set/add/del interface) */ |
26 | 29 | #define FDE_DONT_CLOSE 0x0080 |
@@ -30,6 +33,8 @@ typedef struct fdevent fdevent; | ||
30 | 33 | typedef void (*fd_func)(int fd, unsigned events, void *userdata); |
31 | 34 | |
32 | 35 | /* Allocate and initialize a new fdevent object |
36 | + * Note: use FD_TIMER as 'fd' to create a fd-less object | |
37 | + * (used to implement timers). | |
33 | 38 | */ |
34 | 39 | fdevent *fdevent_create(int fd, fd_func func, void *arg); |
35 | 40 |
@@ -53,6 +58,8 @@ void fdevent_set(fdevent *fde, unsigned events); | ||
53 | 58 | void fdevent_add(fdevent *fde, unsigned events); |
54 | 59 | void fdevent_del(fdevent *fde, unsigned events); |
55 | 60 | |
61 | +void fdevent_set_timeout(fdevent *fde, int64_t timeout_ms); | |
62 | + | |
56 | 63 | /* loop forever, handling events. |
57 | 64 | */ |
58 | 65 | void fdevent_loop(); |
@@ -65,7 +72,7 @@ struct fdevent | ||
65 | 72 | int fd; |
66 | 73 | unsigned short state; |
67 | 74 | unsigned short events; |
68 | - | |
75 | + | |
69 | 76 | fd_func func; |
70 | 77 | void *arg; |
71 | 78 | }; |
@@ -165,7 +165,7 @@ static int sync_start_readtime(int fd, const char *path) | ||
165 | 165 | } |
166 | 166 | |
167 | 167 | static int sync_finish_readtime(int fd, unsigned int *timestamp, |
168 | - unsigned int *mode, unsigned int *size) | |
168 | + unsigned int *mode, unsigned int *size) | |
169 | 169 | { |
170 | 170 | syncmsg msg; |
171 | 171 |
@@ -908,12 +908,12 @@ static int copy_remote_dir_local(int fd, const char *rpath, const char *lpath, | ||
908 | 908 | unsigned int timestamp, mode, size; |
909 | 909 | if (sync_finish_readtime(fd, ×tamp, &mode, &size)) |
910 | 910 | return 1; |
911 | - if (size == ci->size) { | |
911 | + if (size == ci->size) { | |
912 | 912 | /* for links, we cannot update the atime/mtime */ |
913 | 913 | if ((S_ISREG(ci->mode & mode) && timestamp == ci->time) || |
914 | - (S_ISLNK(ci->mode & mode) && timestamp >= ci->time)) | |
914 | + (S_ISLNK(ci->mode & mode) && timestamp >= ci->time)) | |
915 | 915 | ci->flag = 1; |
916 | - } | |
916 | + } | |
917 | 917 | } |
918 | 918 | } |
919 | 919 | #endif |
@@ -23,7 +23,7 @@ implementation to be much more robust. | ||
23 | 23 | |
24 | 24 | |
25 | 25 | --- protocol overview and basics --------------------------------------- |
26 | - | |
26 | + | |
27 | 27 | The transport layer deals in "messages", which consist of a 24 byte |
28 | 28 | header followed (optionally) by a payload. The header consists of 6 |
29 | 29 | 32 bit words which are sent across the wire in little endian format. |
@@ -52,7 +52,7 @@ The identifiers "local-id" and "remote-id" are always relative to the | ||
52 | 52 | reversed. |
53 | 53 | |
54 | 54 | |
55 | - | |
55 | + | |
56 | 56 | --- CONNECT(version, maxdata, "system-identity-string") ---------------- |
57 | 57 | |
58 | 58 | The CONNECT message establishes the presence of a remote system. |
@@ -114,7 +114,7 @@ is used to establish the connection). Nonetheless, the local-id MUST | ||
114 | 114 | not change on later READY messages sent to the same stream. |
115 | 115 | |
116 | 116 | |
117 | - | |
117 | + | |
118 | 118 | --- WRITE(0, remote-id, "data") ---------------------------------------- |
119 | 119 | |
120 | 120 | The WRITE message sends data to the recipient's stream identified by |
@@ -172,7 +172,7 @@ to send across the wire. | ||
172 | 172 | #define A_WRTE 0x45545257 |
173 | 173 | |
174 | 174 | |
175 | - | |
175 | + | |
176 | 176 | --- implementation details --------------------------------------------- |
177 | 177 | |
178 | 178 | The core of the bridge program will use three threads. One thread |
@@ -67,16 +67,16 @@ typedef void (*win_thread_func_t)(void* arg); | ||
67 | 67 | |
68 | 68 | static __inline__ int adb_thread_create( adb_thread_t *thread, adb_thread_func_t func, void* arg) |
69 | 69 | { |
70 | - thread->tid = _beginthread( (win_thread_func_t)func, 0, arg ); | |
71 | - if (thread->tid == (unsigned)-1L) { | |
72 | - return -1; | |
73 | - } | |
74 | - return 0; | |
70 | + thread->tid = _beginthread( (win_thread_func_t)func, 0, arg ); | |
71 | + if (thread->tid == (unsigned)-1L) { | |
72 | + return -1; | |
73 | + } | |
74 | + return 0; | |
75 | 75 | } |
76 | 76 | |
77 | 77 | static __inline__ void close_on_exec(int fd) |
78 | 78 | { |
79 | - /* nothing really */ | |
79 | + /* nothing really */ | |
80 | 80 | } |
81 | 81 | |
82 | 82 | extern void disable_tcp_nagle(int fd); |
@@ -138,7 +138,7 @@ static __inline__ int unix_write(int fd, const void* buf, size_t len) | ||
138 | 138 | |
139 | 139 | static __inline__ int adb_open_mode(const char* path, int options, int mode) |
140 | 140 | { |
141 | - return adb_open(path, options); | |
141 | + return adb_open(path, options); | |
142 | 142 | } |
143 | 143 | |
144 | 144 | static __inline__ int unix_open(const char* path, int options,...) |
@@ -203,7 +203,7 @@ struct fdevent { | ||
203 | 203 | |
204 | 204 | static __inline__ void adb_sleep_ms( int mseconds ) |
205 | 205 | { |
206 | - Sleep( mseconds ); | |
206 | + Sleep( mseconds ); | |
207 | 207 | } |
208 | 208 | |
209 | 209 | extern int adb_socket_accept(int serverfd, struct sockaddr* addr, socklen_t *addrlen); |
@@ -290,7 +290,7 @@ typedef pthread_mutex_t adb_mutex_t; | ||
290 | 290 | |
291 | 291 | static __inline__ void close_on_exec(int fd) |
292 | 292 | { |
293 | - fcntl( fd, F_SETFD, FD_CLOEXEC ); | |
293 | + fcntl( fd, F_SETFD, FD_CLOEXEC ); | |
294 | 294 | } |
295 | 295 | |
296 | 296 | static __inline__ int unix_open(const char* path, int options,...) |
@@ -312,7 +312,7 @@ static __inline__ int unix_open(const char* path, int options,...) | ||
312 | 312 | |
313 | 313 | static __inline__ int adb_open_mode( const char* pathname, int options, int mode ) |
314 | 314 | { |
315 | - return open( pathname, options, mode ); | |
315 | + return open( pathname, options, mode ); | |
316 | 316 | } |
317 | 317 | |
318 | 318 |
@@ -368,11 +368,11 @@ static __inline__ int adb_creat(const char* path, int mode) | ||
368 | 368 | { |
369 | 369 | int fd = creat(path, mode); |
370 | 370 | |
371 | - if ( fd < 0 ) | |
372 | - return -1; | |
371 | + if ( fd < 0 ) | |
372 | + return -1; | |
373 | 373 | |
374 | 374 | close_on_exec(fd); |
375 | - return fd; | |
375 | + return fd; | |
376 | 376 | } |
377 | 377 | #undef creat |
378 | 378 | #define creat ___xxx_creat |
@@ -439,12 +439,12 @@ static __inline__ int adb_socketpair( int sv[2] ) | ||
439 | 439 | |
440 | 440 | static __inline__ void adb_sleep_ms( int mseconds ) |
441 | 441 | { |
442 | - usleep( mseconds*1000 ); | |
442 | + usleep( mseconds*1000 ); | |
443 | 443 | } |
444 | 444 | |
445 | 445 | static __inline__ int adb_mkdir(const char* path, int mode) |
446 | 446 | { |
447 | - return mkdir(path, mode); | |
447 | + return mkdir(path, mode); | |
448 | 448 | } |
449 | 449 | #undef mkdir |
450 | 450 | #define mkdir ___xxx_mkdir |
@@ -739,12 +739,12 @@ int adb_socket_accept(int serverfd, struct sockaddr* addr, socklen_t *addrle | ||
739 | 739 | { |
740 | 740 | FH serverfh = _fh_from_int(serverfd); |
741 | 741 | FH fh; |
742 | - | |
742 | + | |
743 | 743 | if ( !serverfh || serverfh->clazz != &_fh_socket_class ) { |
744 | 744 | D( "adb_socket_accept: invalid fd %d\n", serverfd ); |
745 | 745 | return -1; |
746 | 746 | } |
747 | - | |
747 | + | |
748 | 748 | fh = _fh_alloc( &_fh_socket_class ); |
749 | 749 | if (!fh) { |
750 | 750 | D( "adb_socket_accept: not enough memory to allocate accepted socket descriptor\n" ); |
@@ -757,7 +757,7 @@ int adb_socket_accept(int serverfd, struct sockaddr* addr, socklen_t *addrle | ||
757 | 757 | D( "adb_socket_accept: accept on fd %d return error %ld\n", serverfd, GetLastError() ); |
758 | 758 | return -1; |
759 | 759 | } |
760 | - | |
760 | + | |
761 | 761 | snprintf( fh->name, sizeof(fh->name), "%d(accept:%s)", _fh_to_int(fh), serverfh->name ); |
762 | 762 | D( "adb_socket_accept on fd %d returns fd %d\n", serverfd, _fh_to_int(fh) ); |
763 | 763 | return _fh_to_int(fh); |
@@ -768,7 +768,7 @@ void disable_tcp_nagle(int fd) | ||
768 | 768 | { |
769 | 769 | FH fh = _fh_from_int(fd); |
770 | 770 | int on; |
771 | - | |
771 | + | |
772 | 772 | if ( !fh || fh->clazz != &_fh_socket_class ) |
773 | 773 | return; |
774 | 774 |
@@ -1746,7 +1746,7 @@ void fdevent_loop() | ||
1746 | 1746 | |
1747 | 1747 | /** FILE EVENT HOOKS |
1748 | 1748 | **/ |
1749 | - | |
1749 | + | |
1750 | 1750 | static void _event_file_prepare( EventHook hook ) |
1751 | 1751 | { |
1752 | 1752 | if (hook->wanted & (FDE_READ|FDE_WRITE)) { |
@@ -446,7 +446,7 @@ int recognized_device(usb_handle* handle) { | ||
446 | 446 | } |
447 | 447 | |
448 | 448 | void find_devices() { |
449 | - usb_handle* handle = NULL; | |
449 | + usb_handle* handle = NULL; | |
450 | 450 | char entry_buffer[2048]; |
451 | 451 | char interf_name[2048]; |
452 | 452 | AdbInterfaceInfo* next_interface = (AdbInterfaceInfo*)(&entry_buffer[0]); |