Commit 80dac0f1 authored by hark's avatar hark
Browse files

tcp test

parent bd4c432d
......@@ -10,6 +10,11 @@ CFLAGS= -O0 -march=native -Wall -Wextra -Wno-unused-parameter -Wno-unused-variab
all : c-player c-player-0.10 c-player-debug vartest snowControl s2s s2s-cli bigscreen
tcpclient: tcpclient.c
gcc -DTESTING -DGTK -g tcpclient.c -o tcpclient `pkg-config --cflags --libs gstreamer-interfaces-0.10 gstreamer-pbutils-0.10 gtk+-2.0 gstreamer-0.10` $(CFLAGS)
vartest: vartest.c
gcc -DTESTING -DGTK -g vartest.c snowbin.c wraps.c -o vartest `pkg-config --cflags --libs gstreamer-interfaces-0.10 gstreamer-pbutils-0.10 gtk+-2.0 gstreamer-0.10` $(CFLAGS)
......
......@@ -259,42 +259,29 @@ get_snowvideobin (snowData *sd)
g_object_set (videoscale, "add-borders", TRUE, NULL);
g_object_set (G_OBJECT (capsfilter), "caps", caps, NULL);
/* shmsink */
shmsink = gst_element_factory_make ("shmsink", "shmsink");
// char *controlpipe = NULL;
// asprintf (&controlpipe, "/tmp/%s-control-pipe", feedname);
// printf("SNOWBIN.C control pipe path: %s\n",controlpipe);
/* remove control pipe file */
remove (feed->control_pipe);
g_object_set (shmsink, "socket-path", feed->control_pipe, NULL);
#ifndef GST1
#ifndef GST1 //gst0.10
g_object_set (shmsink, "shm-size", "23224320", NULL);
// g_object_set (shmsink, "shm-size", "40000000", NULL);
#endif
g_object_set (shmsink, "wait-for-connection", FALSE, NULL);
#ifdef GST1
// g_object_set (shmsink, "shm-size", "10000000", NULL);
/* add and link elements in the bin */
gst_bin_add_many (GST_BIN (snowvideobin), queue, videorate, videoscale,
videoconvert, capsfilter, shmsink, NULL);
if( !gst_element_link_many (queue, videorate, videoscale, videoconvert,capsfilter, shmsink, NULL)) {printf("linking snowbin failed");}
#else
/* add and link elements in the bin */
#else //gst0.10
gst_bin_add_many (GST_BIN (snowvideobin), queue, videorate, videoscale,
videoconvert, capsfilter, shmsink, NULL);
gst_element_link_many (queue, videorate, videoscale, videoconvert,
capsfilter, shmsink, NULL);
#endif
vpad = gst_element_get_static_pad (queue, "sink");
......@@ -334,6 +321,53 @@ get_jacksink (int feedid)
return js;
}
extern GstElement *
get_snowsink (int feedid)
{
GstElement *fdsink, *abin;
char *feedname = "feedfuck";
asprintf (&feedname, "feed%u", feedid);
abin = gst_bin_new("snowmix socket");
// file descriptor sink
fdsink = gst_element_factory_make("fdsink","fdsink");
// start nc
int filedes[2];
if (pipe(filedes) == -1)
{
perror("pipe");
exit(1);
}
pid_t pid = fork();
if (pid == -1)
{
perror("fork");
//exit(1);
}
else if (pid == 0)
{
while ((dup2(filedes[1], STDOUT_FILENO) == -1) && (errno == EINTR)) {}
close(filedes[1]);
close(filedes[0]);
printf("executing nc\n");
execl("/bin/nc", "nc", "--stdout", "127.0.0.1", "9999");
perror("execl");
//_exit(1);
}
close(filedes[1]);
printf("fd: %i\n", filedes[0]);
// set filedescriptor
g_object_set( G_OBJECT (fdsink), "fd", filedes[0], NULL);
return abin;
}
extern int
snowbin_init_snowData (PlayerData *s)
{
......
#include <stdio.h>
#include "switchs.h"
int main(int argc, char **argv) {
switchs(argv[1]) {
cases("foo")
cases("bar")
printf("foo or bar (case sensitive)\n");
break;
icases("pi")
printf("pi or Pi or pI or PI (case insensitive)\n");
break;
cases_re("^D.*",0)
printf("Something that start with D (case sensitive)\n");
break;
cases_re("^E.*",REG_ICASE)
printf("Something that start with E (case insensitive)\n");
break;
cases("1")
printf("1\n");
cases("2")
printf("2\n");
break;
defaults
printf("No match\n");
break;
} switchs_end;
return 0;
}
/*
** client.c -- a stream socket client demo
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <arpa/inet.h>
#define PORT "9999" // the port client will be connecting to
#define MAXDATASIZE 1000 // max number of bytes we can get at once
// get sockaddr, IPv4 or IPv6:
void *get_in_addr(struct sockaddr *sa)
{
if (sa->sa_family == AF_INET) {
return &(((struct sockaddr_in*)sa)->sin_addr);
}
return &(((struct sockaddr_in6*)sa)->sin6_addr);
}
int
setNonblocking(int fd)
{
int flags;
/* If they have O_NONBLOCK, use the Posix way to do it */
/* Fixme: O_NONBLOCK is defined but broken on SunOS 4.1.x and AIX 3.2.5. */
if (-1 == (flags = fcntl(fd, F_GETFL, 0)))
flags = 0;
return fcntl(fd, F_SETFL, flags | SOCK_NONBLOCK);
}
extern int
open_client_socket(char *host, char *port)
{
int sockfd;
char buf[MAXDATASIZE];
struct addrinfo hints, *servinfo, *p;
int rv;
char s[INET6_ADDRSTRLEN];
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
if ((rv = getaddrinfo(host, port, &hints, &servinfo)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
return 1;
}
// loop through all the results and connect to the first we can
for(p = servinfo; p != NULL; p = p->ai_next) {
if ((sockfd = socket(p->ai_family, p->ai_socktype,
p->ai_protocol)) == -1) {
perror("client: socket");
continue;
}
if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
close(sockfd);
perror("client: connect");
continue;
}
break;
}
if (p == NULL) {
fprintf(stderr, "client: failed to connect\n");
return 2;
}
//set nonblocking
fcntl(sockfd, F_SETFL, O_NONBLOCK);
inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
s, sizeof s);
printf("client: connecting to %s\n", s);
freeaddrinfo(servinfo); // all done with this structure
return sockfd;
}
void
readsock(int sock)
{
int n, i;
char *result;
char buf[MAXDATASIZE];
i=0;
// read
while ( i < 3 )
{
i++;
n = recv(sock, buf, MAXDATASIZE-1, 0);
printf("numbytes: %i\n ", n);
if (n == 0)
{
//exit(1);
printf("socket dissapeared");
} else if (n < 0) {
switch (errno){
case EAGAIN:
printf("wouldblock\n ");
break;
default:
printf("error: %i\n ", errno);
break;
}
} else {
buf[n] = '\0';
printf("client: received '%s'\n",buf);
}
sleep(1);
}
}
extern char *
sendcommand(int sock, char *cmd)
{
int numbytes;
char *result;
char buf[MAXDATASIZE];
printf("sending: %s", cmd);
// write
write(sock, cmd, sizeof(&cmd));
sleep(1);
readsock(sock);
// sleep(1);
// readsock(sock);
}
int main(int argc, char *argv[])
{
int sock;
//char buf[MAXDATASIZE];
if (argc != 2) {
fprintf(stderr,"usage: client hostname\n");
exit(1);
}
sock = open_client_socket("127.0.0.1", "9999");
sendcommand(sock, "hello1\n");
sendcommand(sock, "hello2\n");
sendcommand(sock, "hello3\n");
sendcommand(sock, "hello4\n");
close(sock);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment