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

« back to all changes in this revision

Viewing changes to tests/websockets_bi_side_bigdata.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

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
#if EMSCRIPTEN
 
12
#include <emscripten.h>
 
13
#endif
 
14
 
 
15
#include "websockets_bigdata.h"
 
16
 
 
17
#define EXPECTED_BYTES 5
 
18
 
 
19
void stall(void *arg) {
 
20
}
 
21
 
 
22
int main(void)
 
23
{
 
24
  struct sockaddr_in stSockAddr;
 
25
  int Res;
 
26
  int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
 
27
 
 
28
  if (-1 == SocketFD)
 
29
  {
 
30
    perror("cannot create socket");
 
31
    exit(EXIT_FAILURE);
 
32
  }
 
33
 
 
34
  memset(&stSockAddr, 0, sizeof(stSockAddr));
 
35
 
 
36
  stSockAddr.sin_family = AF_INET;
 
37
  stSockAddr.sin_port = htons(SOCKK);
 
38
  Res = inet_pton(AF_INET, "127.0.0.1", &stSockAddr.sin_addr);
 
39
 
 
40
  if (0 > Res) {
 
41
    perror("error: first parameter is not a valid address family");
 
42
    close(SocketFD);
 
43
    exit(EXIT_FAILURE);
 
44
  } else if (0 == Res) {
 
45
    perror("char string (second parameter does not contain valid ipaddress)");
 
46
    close(SocketFD);
 
47
    exit(EXIT_FAILURE);
 
48
  }
 
49
 
 
50
  printf("connect..\n");
 
51
 
 
52
  if (-1 == connect(SocketFD, (struct sockaddr *)&stSockAddr, sizeof(stSockAddr))) {
 
53
    perror("connect failed");
 
54
    close(SocketFD);
 
55
    exit(EXIT_FAILURE);
 
56
  }
 
57
 
 
58
  printf("send..\n");
 
59
 
 
60
  char *data = generateData();
 
61
  send(SocketFD, data, DATA_SIZE, 0);
 
62
 
 
63
  printf("stall..\n");
 
64
 
 
65
  emscripten_set_main_loop(stall, 1, 0);
 
66
 
 
67
  return EXIT_SUCCESS;
 
68
}
 
69