~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/sockets/test_sockets_select_server_down_server.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-09-20 22:44:35 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130920224435-apuwj4fsl3fqv1a6
Tags: 1.5.6~20130920~6010666-1
* New snapshot release
* Update the list of supported architectures to the same as libv8
  (Closes: #723129)
* emlibtool has been removed from upstream.
* Fix warning syntax-error-in-dep5-copyright
* Refresh of the patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <assert.h>
 
2
#include <errno.h>
 
3
#include <fcntl.h>
 
4
#include <stdio.h>
 
5
#include <stdlib.h>
 
6
#include <string.h>
 
7
#include <unistd.h>
 
8
#include <arpa/inet.h>
 
9
#include <netinet/in.h>
 
10
#include <sys/ioctl.h>
 
11
#include <sys/types.h>
 
12
#include <sys/socket.h>
 
13
#if EMSCRIPTEN
 
14
#include <emscripten.h>
 
15
#endif
 
16
 
 
17
void main_loop(void *arg) {
 
18
}
 
19
 
 
20
int main() {
 
21
  struct sockaddr_in addr;
 
22
  int res;
 
23
  int serverfd;
 
24
 
 
25
  // create the socket
 
26
  serverfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
 
27
  if (serverfd == -1) {
 
28
    perror("cannot create socket");
 
29
    exit(EXIT_FAILURE);
 
30
  }
 
31
  fcntl(serverfd, F_SETFL, O_NONBLOCK);
 
32
 
 
33
  // bind to the supplied port
 
34
  memset(&addr, 0, sizeof(addr));
 
35
  addr.sin_family = AF_INET;
 
36
  addr.sin_port = htons(SOCKK);
 
37
  if (inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr) != 1) {
 
38
    perror("inet_pton failed");
 
39
    exit(EXIT_FAILURE);
 
40
  }
 
41
 
 
42
  res = bind(serverfd, (struct sockaddr *)&addr, sizeof(addr));
 
43
  if (res == -1) {
 
44
    perror("bind failed");
 
45
    exit(EXIT_FAILURE);
 
46
  }
 
47
 
 
48
  close(serverfd);
 
49
 
 
50
#if EMSCRIPTEN
 
51
  emscripten_set_main_loop(main_loop, 60, 0);
 
52
#else
 
53
  while (1) main_loop(NULL); sleep(1);
 
54
#endif
 
55
 
 
56
  return EXIT_SUCCESS;
 
57
}