1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <winsock2.h>
#include <string.h>
#include <io.h>
#include <time.h>
#include <memory.h>
#include <windows.h>
#include <windowsx.h>
#pragma comment(lib, "ws2_32.lib")
static char rBuf[2048];
int sockFd;
int cpaCommOpenConnectionInet(void /*int fd*/)
{
static const char __func__[] = "cpaCommOpenConnectionInet";
/* connect to socket */
struct sockaddr_in addr;
//struct sigaction action;
struct hostent* server;
sockFd = socket( AF_INET, SOCK_STREAM, 0 );
memset( &addr, 0, sizeof(addr) );
server = gethostbyname("10.160.41.89");
addr.sin_family = AF_INET;
memcpy((char *) server->h_addr, (char *) &addr.sin_addr.s_addr, server->h_length);
addr.sin_port = htons(1096);
if ( connect( sockFd, (struct sockaddr*) &addr, sizeof( addr ) ) == 0 )
{
printf("Success to connect with TAPI Server \n" );
//cpaSetSocketBlock(sockFd, 1 );
// action.sa_sigaction = cpaAsyncSignal;
//action.sa_flags = /*SA_SIGINFO*/SIGILL;
//sigemptyset(&action.sa_mask);
if (signal(sockFd/*fd*/,(void*)SIGILL) < 0) { //if(sigaction(SIGNAL_IO, &action, NULL) < 0) {
perror("sigaction");
exit(1);
}
cpaTriggerAsyncRead(sockFd, sizeof(cpaMessageHeaderT), CPA_MESSAGE_HEADER);
}
else
{
printf("Fail to connect with TAPI Server, %s \n", strerror(errno) );
cpaCloseSocketFd( sockFd );
sockFd = -1;
exit(-1);
}
return sockFd;
} |
Partager