Example #1
0
bool *number_to_bin(int i){	/*integer to digital convertion*/
	
	int divisor, quocient,c,tmp;

	bool converted,temporary;
	bool *word=alloc_word();	/*final word*/

	/*now we fill the word with zeroes*/
	zero_stream(word,WORD_SIZE);


	divisor=i;	
	converted=false; /*initially, the number is not converted*/

	for(c=0;c<=WORD_SIZE;c++){  /*plus one execution (<=), just in case that number ocupe all the WORD_SIZE space*/
		if(converted==false){
			if((quocient!=1)&&(quocient!=0)){ /*if the process is not in the end*/

				quocient=(divisor-(divisor%2))/2;
			
				word[c]=(divisor%2==0)?false:true;
				divisor=quocient;

			
			}else{
				*(word+c)=(quocient==1)?true:false;

				/*this will make the for restart( but now, executing the first else )*/
				converted=true;
				tmp=c;	/*tmp backup the value of c*/

				break;
			}
		}else{	/*this will reverse the order(basic number to digital convertion)*/

				 if(c<=((tmp-(tmp%2))/2)){ /*if its less or equal the middle/last element*/

				 	/*not exchange the value if its impar and reached the middle element,(tmp starts in 0) and then stop*/
					if((tmp%2==0)&&(c==(tmp-(tmp%2))/2)){

						break;
					}else{
					
					/*this exchange the position*/

					temporary=word[c];
					word[c]=word[tmp-c];
					word[tmp-c]=temporary;
					}
				}else{
					break;

				}

		}
	}


	if(tmp!=WORD_SIZE){
		/*now we simply shift the number to the top*/
		for(c=0;c<=tmp;c++){

			word[WORD_SIZE-1-c]=word[tmp-c];
			word[tmp-c]=false;

		
		}
	}

		

	return word;
}
Example #2
0
File: test.c Project: jcaose/evcom
int
main (void)
{
  fprintf(stderr, "sizeof(evcom_server): %d\n", (int)sizeof(evcom_server));
  fprintf(stderr, "sizeof(evcom_stream): %d\n", (int)sizeof(evcom_stream));
  fprintf(stderr, "sizeof(evcom_reader): %d\n", (int)sizeof(evcom_reader));
  fprintf(stderr, "sizeof(evcom_writer): %d\n", (int)sizeof(evcom_writer));

  evcom_ignore_sigpipe();

#if EVCOM_HAVE_GNUTLS
  gnutls_global_init();

  gnutls_dh_params_init (&dh_params);

  fsync(fileno(stderr));
  gnutls_dh_params_generate2 (dh_params, DH_BITS);

  gnutls_anon_allocate_server_credentials (&server_credentials);
  gnutls_anon_set_server_dh_params (server_credentials, dh_params);
#endif


  struct sockaddr_in tcp_address;
  memset(&tcp_address, 0, sizeof(struct sockaddr_in));
  tcp_address.sin_family = AF_INET;
  tcp_address.sin_port = htons(PORT);
  tcp_address.sin_addr.s_addr = INADDR_ANY;

  use_tls = 0;

  fprintf(stderr, "pair_pingpong use_pipe=1: ");
  assert(pair_pingpong(1) == 0);
  fprintf(stderr, "\n");

  fprintf(stderr, "pair_pingpong use_pipe=0: ");
  assert(pair_pingpong(0) == 0);
  fprintf(stderr, "\n");

  fprintf(stderr, "zero_stream tcp: ");
  assert(zero_stream((struct sockaddr*)&tcp_address, 5*1024*1024) == 0);
  fprintf(stderr, "\n");

  fprintf(stderr, "pipe_stream: ");
  assert(pipe_stream() == 0);
  fprintf(stderr, "\n");

  fprintf(stderr, "pingpong tcp: ");
  assert(pingpong((struct sockaddr*)&tcp_address) == 0);
  fprintf(stderr, "\n");

  fprintf(stderr, "connint tcp: ");
  assert(connint((struct sockaddr*)&tcp_address) == 0);
  fprintf(stderr, "\n");

#if EVCOM_HAVE_GNUTLS
  use_tls = 1;

  fprintf(stderr, "zero_stream ssl: ");
  assert(zero_stream((struct sockaddr*)&tcp_address, 50*1024) == 0);
  fprintf(stderr, "\n");

  fprintf(stderr, "pair_pingpong ssl use_pipe=1: ");
  assert(pair_pingpong(1) == 0);
  fprintf(stderr, "\n");

  fprintf(stderr, "pair_pingpong ssl use_pipe=0: ");
  assert(pair_pingpong(0) == 0);
  fprintf(stderr, "\n");

  fprintf(stderr, "pingpong ssl: ");
  assert(pingpong((struct sockaddr*)&tcp_address) == 0);
  fprintf(stderr, "\n");

  fprintf(stderr, "connint ssl: ");
  assert(connint((struct sockaddr*)&tcp_address) == 0);
  fprintf(stderr, "\n");

#endif

  struct sockaddr *unix_address;

  use_tls = 0;

  fprintf(stderr, "pingpong unix: ");
  unix_address = create_unix_address();
  assert(pingpong(unix_address) == 0);
  free_unix_address(unix_address);
  fprintf(stderr, "\n");

  fprintf(stderr, "connint unix: ");
  unix_address = create_unix_address();
  assert(connint(unix_address) == 0);
  free_unix_address(unix_address);
  fprintf(stderr, "\n");

#if EVCOM_HAVE_GNUTLS
  use_tls = 1;

  fprintf(stderr, "pingpong unix ssl: ");
  unix_address = create_unix_address();
  assert(pingpong(unix_address) == 0);
  free_unix_address(unix_address);
  fprintf(stderr, "\n");

  fprintf(stderr, "connint unix ssl: ");
  unix_address = create_unix_address();
  assert(connint(unix_address) == 0);
  free_unix_address(unix_address);
  fprintf(stderr, "\n");
#endif

  return 0;
}