Commit | Line | Data |
---|---|---|
d3372da9 | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | |
3 | #include <sys/poll.h> | |
219dfc0e FT |
4 | #include <time.h> |
5 | #include <sys/time.h> | |
d3372da9 | 6 | |
7 | #include <doldaconnect/uilib.h> | |
8 | #include <doldaconnect/uimisc.h> | |
219dfc0e | 9 | #include <doldaconnect/utils.h> |
d3372da9 | 10 | |
cb972e81 | 11 | int done; |
219dfc0e | 12 | double btime; |
cb972e81 | 13 | |
d3372da9 | 14 | void authcallback(int err, wchar_t *reason, void *data) |
15 | { | |
219dfc0e | 16 | printf("auth: %f\n", ntime() - btime); |
d3372da9 | 17 | printf("Logged in: %i\n", err); |
219dfc0e | 18 | exit(0); |
cb972e81 | 19 | dc_queuecmd(NULL, NULL, L"quit", NULL); |
d3372da9 | 20 | } |
21 | ||
22 | int main(int argc, char **argv) | |
23 | { | |
d3372da9 | 24 | struct pollfd pfd; |
cb972e81 | 25 | int fd; |
d3372da9 | 26 | struct dc_response *resp; |
d3372da9 | 27 | |
219dfc0e | 28 | btime = ntime(); |
d3372da9 | 29 | dc_init(); |
219dfc0e | 30 | printf("init: %f\n", ntime() - btime); |
65bf229b | 31 | fd = dc_connect(NULL); |
d3372da9 | 32 | done = 0; |
33 | while(!done) | |
34 | { | |
35 | pfd.fd = fd; | |
36 | pfd.events = POLLIN; | |
37 | if(dc_wantwrite()) | |
38 | pfd.events = POLLOUT; | |
39 | if(poll(&pfd, 1, -1) < 0) | |
40 | { | |
41 | perror("poll"); | |
42 | exit(1); | |
43 | } | |
44 | if((pfd.revents & POLLIN) && dc_handleread()) | |
45 | done = 1; | |
46 | if((pfd.revents & POLLOUT) && dc_handlewrite()) | |
47 | done = 1; | |
48 | while((resp = dc_getresp()) != NULL) | |
49 | { | |
bf46d8f1 | 50 | if(!wcscmp(resp->cmdname, L".connect")) |
d3372da9 | 51 | { |
219dfc0e | 52 | printf("conn: %f\n", ntime() - btime); |
1157d12b | 53 | printf("Connected: %i\n", resp->code); |
e5c8b0ca | 54 | if(resp->code == 201) |
1157d12b | 55 | dc_loginasync(NULL, 1, NULL, authcallback, NULL); |
d3372da9 | 56 | } |
57 | dc_freeresp(resp); | |
58 | } | |
59 | } | |
219dfc0e | 60 | printf("fini: %f\n", ntime() - btime); |
d3372da9 | 61 | dc_cleanup(); |
219dfc0e | 62 | printf("exit: %f\n", ntime() - btime); |
d3372da9 | 63 | return(0); |
64 | } |