示例#1
0
int callback(void *arg) {
	Socket_t S = (Socket_t)arg;
	String_t Str = tb_String(NULL);
	int i;

	tb_trace(TB_WARN, "Server: New cx (%p)\n", arg);
	tb_Dump(S);
	fflush(stderr);
	tb_readSock(S, Str, MAX_BUFFER);

	tb_trace(TB_WARN, "Server: recv<%S>\n", Str);

	for(i=10; i>0; i--) {
		char buf[256];
		snprintf(buf, 255, "cb[%d] countdown: %d ...\n", pthread_self(), i);
		sleep(1);
		tb_writeSock(S, buf);
	}
	tb_writeSock(S, "BYE");
	
	tb_trace(TB_WARN, "Server: exit callback\n");
	tb_Free(Str);

	return TB_OK;
}
示例#2
0
int callback(void *arg) {
	Socket_t S = (Socket_t)arg;
	String_t Str = tb_String(NULL);

	tb_trace(TB_WARN, "Server: New cx \n");
	tb_Dump(S);

	// -- for educative purpose only. -optional- behaviour
	// setup timeout to 5mn 
	tb_setSockTO(S, 5*60, 0);
	// setup max allowed threads to 5
	tb_setServMAXTHR(S, 5);
	// disable Nagle's algo
	tb_setSockNoDelay(S);
	// -------------
	tb_Dump(S);

	tb_readSock(S, Str, MAX_BUFFER);

	tb_trace(TB_WARN, "Server: recv<%s>\n", tb_toStr(Str));
	tb_writeSock(S, "BYE");
	tb_trace(TB_WARN, "Server: exit callback\n");
	tb_Free(Str);

	return TB_OK;
}
示例#3
0
int callback(void *arg) {
	Socket_t S = (Socket_t)arg;
	String_t Str = tb_String(NULL);

	tb_trace(TB_WARN, "Server: New cx \n");
	tb_setSockTO(S, 5*60, 0);
	tb_setServMAXTHR(S, 5);
	// -------------
	tb_readSock(S, Str, MAX_BUFFER);
	tb_trace(TB_WARN, "Server: recv<%s>\n", tb_toStr(Str));
	tb_writeSock(S, "BYE");
	tb_trace(TB_WARN, "Server: exit callback\n");
	tb_Free(Str);

	return TB_OK;
}
示例#4
0
int main(int argc, char **argv) {
	Hash_t H;
	Socket_t Server = tb_Socket(TB_TCP_IP, "localhost", 5555);

	pthread_t pt;
	pthread_attr_t attr;
	char buff[MAX_BUFFER+1];
	int i, rc;
	char datum[] = "hello shiny world !";
	int acks = 0;
	int max = 5000;

	tb_errorlevel = TB_INFO;

	tb_setServMAXTHR(Server, 5);

	if((rc = tb_initServer(Server, callback, NULL)) != TB_OK) {
		tb_trace(TB_WARN, "init server failed\n");
		return 1;
	}

	tb_Dump(Server);

	tb_Accept( Server );

	return 0;
}
/* Initialization */
int tb_init(unsigned long options)
{
	if (tb_control) {
		++tb_control->nusers;
		return 0;
	}
	tb_control = (tb_control_t *)TB_MALLOC(tb_control_size());
	if (!tb_control)
		return -1;
	memset(tb_control, 0, tb_control_size());
	tb_control->nusers = 1;

	/* Measure self-delay */
	tb_trace(0, 0, 0);
	tb_trace(0, 0, 0);
	tb_control->self_delay = tb_control->entry[1].ts - tb_control->entry[0].ts;
	tb_control->pos = tb_control->count = 0;
	tb_control->options = options;
	return 0;
}
示例#6
0
int main(int argc, char **argv) {
	Vector_t V, W;
	String_t S, T;

	void *p;

	char str[] = "10803551 10817246 12120887 13158625 13158627 13158628 13158630 13158632 13158633 13158634 13158635 13158637";

	char str2[] = "9175671 9205348 9261196 9327975 9328060 9330988 9331049 9334260 9387462 9387554 9439690 9440498 9570101 9570134 10086719 10103019 10465797 10466474 10466665 10584336 10586793 10600940 10631836 10634039 10654429 10827350 10829669 10838160 11139404 11142142 11178380 11178385 11475166 11475684 11507366 13070161 13073652 13089439 13101587";

	setenv("TB_MEM_DEBUG", "vector.dbg", 1);
	//	tb_memDebug();

	/*
	tb_setGetNameFnc(getmyname);
	tb_setTraceFnc(my_trace);

	tb_errorlevel = TB_DEBUG;
	*/


	V = tb_Vector();
	tb_tokenize(V, str, " ", 0);
	tb_Dump(V);
	while(tb_getSize(V)) {
		tb_Object_t O = tb_Pop(V);
		tb_Free(O);
		//		tb_Dump(V);
	}
	//	tb_Dump(V);
	tb_Clear(V);
	tb_tokenize(V, str2, " ", 0);
	tb_Dump(V);
	while(tb_getSize(V)) {
		tb_Object_t O = tb_Pop(V);
		tb_Free(O);
		tb_Dump(V);
	}
	tb_Dump(V);

	tb_Free(V);

	V = tb_Vector();

	S = tb_String("%s", "1/2/3/4/5/6/7/8/9");
	tb_Dump(S);
	tb_warn("tb_tokenize rc = %d\n", 
					 tb_tokenize(V, tb_toStr(S), "/", 0));
	tb_Dump(V);




	{
		Vector_t W;
		//		tb_errorlevel = TB_DEBUG;

		tb_Free(S);
		S = tb_Marshall(V);
		fprintf(stderr, "-->\n%s\n<--\n", S2sz(S));
		W = tb_unMarshall(S);
		tb_Dump(W);
	}



	tb_StrAdd(tb_Clear(S), 0, "%s", "Blip"); 

	T = tb_String("%s", "un deux 'trois quatre' ' cinq"); 

	tb_Clear(V);
	tb_Dump(V);
	tb_tokenize(V, tb_toStr(S), "/", 0);
	tb_Dump(V);


	fprintf(stderr, "#0: [%s]\n", tb_toStr(V,0));


	W = tb_Vector();
	tb_tokenize(W, tb_toStr(T), " ", TK_ESC_QUOTES);
	tb_Dump(W);

	//	exit(0);

	tb_Replace(W, S, 5);
	tb_Replace(W, S, 2);
	tb_Dump(W);
	tb_Dump(tb_Pop(W));
	tb_Dump(W);
	tb_Dump(tb_Shift(W));
	tb_Dump(W);
	tb_StrAdd(tb_Clear(T), 0, "%s", "Bloup"); 
	tb_Unshift(W, T);
	tb_Dump(W);
	tb_Free(V);
	V = tb_Clone(W);
	tb_Dump(V);
	tb_Dump(tb_Sort(V, NULL));
	tb_Dump(tb_Reverse(V));
	tb_Free(tb_Get(V, 1));
	tb_Dump(V);
	tb_Remove(V, 0);
	tb_Dump(V);
	tb_trace(TB_WARN, "2str <%s>\n", tb_toStr(V,0));
	tb_Free(V);
	tb_Free(S);

	fm_Dump();
	
	//	*/
	return 0;
}
示例#7
0
int main(int argc, char **argv) {

	int test_ssl   = 1;

	int i;
	tb_profile("Version: %s", tb_getVersion()); 
	tb_profile("Build: %s", tb_getBuild()); 

	tb_errorlevel = TB_DEBUG;

	if(test_ssl) {
		//		Socket_t ssl  = tb_Socket(TB_TCP_IP, "spg-test.aix75.cvf", 443);
		Socket_t sslServ  = tb_Socket(TB_TCP_IP, "", 44443);
		Socket_t ssl  = tb_Socket(TB_TCP_IP, "mail.orange.fr", 443);
		String_t S  = tb_String(NULL); 
		tb_profile(" ------------------- test SSL --------\n");

		//		tb_initSSL( ssl, SSL3, ".", "ca.crt", "client1.crt", "client1.key", NULL);
		//		tb_initSSL( ssl, SSL3, ".", "ca.crt", "wrong.crt", "wrong.key", NULL);
		/*
		tb_initSSL( ssl, 
								SSL3, 
								"/tmp", 
								//"wrong.crt", 
								"tutu/ca.crt", 
								"/tmp/client1.pem", // full path to pem file
								"webhelp", 
								NULL);// cipher
		*/

		tb_SSL_initSockServer(sslServ, callback, NULL, 
											SSL3, ".", "ca.crt", "wrong.pem", "ppasswd", NULL);
		tb_SSL_Accept(sslServ);


		tb_initSSL( ssl, 
								SSL3, 
								"/", 
								//"wrong.crt", 
								"verisign.pem", 
								NULL, // "/tmp/client1.pem", // full path to pem file
								NULL, //"webhelp", 
								NULL);// cipher



		for(i=1;i<2;i++) {

			tb_Connect(ssl, 1, 1);
			tb_setSockTO(ssl, 10,10);
		
			if(tb_getSockStatus(ssl) == TB_CONNECTED) {
				tb_profile("writesock rc: %d\n", tb_writeSock(ssl, "GET /iwsroot/main_logoff_admlogin.asp"));
				shutdown(tb_getSockFD(ssl), 1);
				while( tb_readSock(ssl, S, 1024) >0 );
				tb_profile("readsock read %d bytes\n", tb_getSize(S));
				fprintf(stderr, "client: got <%s>\n", S2sz(S));
				tb_profile(" ------------------- test SSL done --------\n");
			} else {
				tb_trace(TB_WARN, "Not connected !!\n");
			}
			tb_Clear(ssl);
			tb_Clear(S);
		}
	}


	return 0;
}