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

« back to all changes in this revision

Viewing changes to tests/sockets/webrtc_host.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 <errno.h>
 
2
#include <sys/types.h>
 
3
#include <sys/socket.h>
 
4
#include <netinet/in.h>
 
5
#include <arpa/inet.h>
 
6
#include <stdio.h>
 
7
#include <stdlib.h>
 
8
#include <string.h>
 
9
#include <unistd.h>
 
10
#include <sys/ioctl.h>
 
11
#include <assert.h>
 
12
#if EMSCRIPTEN
 
13
#include <emscripten.h>
 
14
#endif
 
15
 
 
16
#define EXPECTED_BYTES 5
 
17
#define BUFLEN 16
 
18
 
 
19
int result = 0;
 
20
int sock;
 
21
char buf[BUFLEN];
 
22
char expected[] = "emscripten";
 
23
struct sockaddr_in si_host,
 
24
                   si_peer;
 
25
struct iovec iov[1];                   
 
26
struct msghdr hdr;
 
27
int done = 0;
 
28
 
 
29
void iter(void* arg) {
 
30
  int n;
 
31
  n = recvmsg(sock, &hdr, 0);
 
32
 
 
33
  if(0 < n) {
 
34
    done = 1;
 
35
    fprintf(stderr, "received %d bytes: %s", n, (char*)hdr.msg_iov[0].iov_base);
 
36
 
 
37
    shutdown(sock, SHUT_RDWR);
 
38
    close(sock);
 
39
 
 
40
#if EMSCRIPTEN
 
41
    int result = 1;
 
42
    REPORT_RESULT();
 
43
    exit(EXIT_SUCCESS);
 
44
    emscripten_cancel_main_loop();
 
45
#endif
 
46
  } else if(EWOULDBLOCK != errno) {
 
47
    perror("recvmsg failed");
 
48
    exit(EXIT_FAILURE);
 
49
    emscripten_cancel_main_loop();
 
50
  }
 
51
}
 
52
 
 
53
int main(void)
 
54
{
 
55
  memset(&si_host, 0, sizeof(struct sockaddr_in));
 
56
  memset(&si_peer, 0, sizeof(struct sockaddr_in));
 
57
 
 
58
  si_host.sin_family = AF_INET;
 
59
  si_host.sin_port = htons(8991);
 
60
  si_host.sin_addr.s_addr = htonl(INADDR_ANY);
 
61
 
 
62
  if(-1 == (sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP))) {
 
63
    perror("cannot create host socket");
 
64
    exit(EXIT_FAILURE);
 
65
  }
 
66
 
 
67
  if(-1 == bind(sock, (struct sockaddr*)&si_host, sizeof(struct sockaddr))) {
 
68
    perror("cannot bind host socket");
 
69
    exit(EXIT_FAILURE);
 
70
  }
 
71
  
 
72
  iov[0].iov_base = buf;
 
73
  iov[0].iov_len = sizeof(buf);
 
74
  
 
75
  memset (&hdr, 0, sizeof (struct msghdr));
 
76
 
 
77
  hdr.msg_name = &si_peer;
 
78
  hdr.msg_namelen = sizeof(struct sockaddr_in);
 
79
  hdr.msg_iov = iov;
 
80
  hdr.msg_iovlen = 1;
 
81
 
 
82
#if EMSCRIPTEN
 
83
  emscripten_set_main_loop(iter, 0, 0);
 
84
#else
 
85
  while (!done) iter(NULL);
 
86
#endif
 
87
 
 
88
  return EXIT_SUCCESS;
 
89
}
 
 
b'\\ No newline at end of file'