Ejemplo n.º 1
0
Table::Table(int descE,int descR,int maxJ, int miseDep){
  cout<<"constructeur"<<endl;
  //Partie constructeur reseau
  descEnvoie=descE;
  descRecu=descR;
  isServeur=true;
  descMax=descRecu;
  brPub = Sock(SOCK_STREAM,(short)0,0);
  if(brPub.good())
    descTable = brPub.getsDesc();
  else{
    cout<<"Probleme desc"<<endl;
    exit(1);
  }
  if(listen(descTable,10) == -1){
    cout<<"erreur de creation Boite Publique"<<endl;
    exit(1);
  }
  char portChar[20]="";
  sprintf(portChar,"%d",brPub.returnPort());
  write(descEnvoie,portChar,20);
  if(descTable>descMax)
    descMax=descTable;
  //Partie constructeur des joueurs
  nbJoueur=0;
  nbJMax = maxJ;
  joueurEnListe=0;
  nbJAllIn=0;
  prochainAMiser=0;
  dernierAMiser=0;
  joueurs=new Joueur*[nbJMax];
  for(int i=0;i<nbJMax;i++){
    joueurs[i]=NULL;
  }
  actif=new bool[nbJMax];
  for(int i=0;i<nbJMax;i++){
    actif[i]=false;
  }
  //Partie constructeur poker
  partieEnCours=false;
  dealer=-1;
  petiteBlind=-1;
  grosseBlind=-1;
  aJouer=false;
  miseMin = miseDep;
  mise = miseMin;
  pot = 0;
  instanceAllIn=false;
  classementJoueurs=new int*[nbJMax];
  for(int i=0;i<nbJMax;i++){
    classementJoueurs[i]=new int[2];
  }

}
Ejemplo n.º 2
0
int CHttpRequest::Post(CUrl& iUrl, const CString& RawData){
  CString Server;
  int Port;  		       
  if (ProxyURL.StrLength() && Proxy.isValid()) {
    Server = Proxy.GetHost();
    Port = Proxy.GetPortValue();
  } else if (iUrl.isValid()) {
    Server = iUrl.GetHost();
    Port = iUrl.GetPortValue();
  } else return 0;
  inetSocket Sock(Port, Server);
  if (wsLastError.StrLength()) return 0;
  char iE[] = "xxxx\0"; sprintf(iE, "%c%c", 13, 10);  
  return PostHTTP(iUrl, RawData, iE, Sock);
}
Ejemplo n.º 3
0
Table::Table(int JoueurMax){
    nbJMax = JoueurMax;
    miseMin = 0;
    pot = 0;

    brPub = Sock(SOCK_STREAM, 0);
    if(brPub.good())
        descTable = brPub.getsDesc();
    else{
        cout<<"Probleme desc"<<endl;
        exit(1);
    }
    if(listen(descTable,JoueurMax) == -1){
        cout<<"erreur file"<<endl;
        exit(1);
    }
}
Ejemplo n.º 4
0
Table::Table(){
    nbJMax = 9;
    miseMin = 0;
    pot = 0;

    brPub = Sock(SOCK_STREAM, 0);
    if(brPub.good())
        descTable = brPub.getsDesc();
    else{
        cout<<"Probleme desc"<<endl;
        exit(1);
    }
    if(listen(descTable,10) == -1){
        cout<<"erreur de creation Boite Publique"<<endl;
        return 0;
    }
}
int main(int argc, char **argv)
{
	int fd;
	socklen_t len;
	struct sock_opts *ptr;

	for(ptr = sock_opts; ptr->opt_str != NULL; ptr++)
	{
		printf("%s: ", ptr->opt_str);
		if(ptr->opt_val_str == NULL)
			printf("(undefined)\n");
		else
		{
			switch(ptr->opt_level)
			{
				case SOL_SOCKET:
				case IPPROTO_IP:			
				case IPPROTO_TCP:
					fd = Socket(AF_INET, SOCK_STREAM, 0);
					break;
#ifdef IPV6
				case IPPROTO_IPV6:
					fd = Sock(AF_INET6, SOCK_STREAM, 0);
					break;
#endif
#ifdef IPPROTO_SCTP
				case IPPROTO_SCTP:
					fd = Socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
					break;
#endif
				default:
					err_quit("Can't create fd for level %d\n", ptr->opt_level);
			}
			
			len = sizeof(val);
			if(getsockopt(fd, ptr->opt_level, ptr->opt_name, &val, &len) == -1)
				err_ret("getsockopt error");
			else
				printf("default = %s\n", (*ptr->opt_val_str)(&val, len));

			close(fd);
		}

	}
	return 0;
}
Ejemplo n.º 6
0
int CHttpRequest::Execute(CUrl& iUrl){
#ifdef _U_DEBUG
    cout << "CHttpRequest::Execute()" << endl;
#endif

    RHeader.Free();
    RData.Free();
    RStatus.Free();
    RStatusValue = -1;
    RedirectVector.Clear();

    CString Server;
    int Port;       
    if (ProxyURL.StrLength() && Proxy.isValid()) {
      Server = Proxy.GetHost();
      Port = Proxy.GetPortValue();
    } else if (iUrl.isValid()) {
      Server = iUrl.GetHost();
      Port = iUrl.GetPortValue();
    } else {
      RStatusValue = HTTPR_USER + 1;
      return 0;
    }
#ifdef _U_DEBUG
    cout << "CHttpRequest::Execute() - creating inetSocket" << endl;
#endif
    inetSocket Sock(Port, Server);
    if (wsLastError.StrLength()) {
#ifdef _U_DEBUG
      cout << "CHttpRequest::Execute() - ERROR at inetSocket - " << wsLastError << endl;
#endif
      RStatusValue = HTTPR_USER + 2;      
      return 0;
    }
#ifdef _U_DEBUG
    cout << "CHttpRequest::Execute() - inetSocket created" << endl;
#endif
    char iE[] = "xxxx\0"; sprintf(iE, "%c%c", 13, 10);  
    
    if (!GetHTTP10(iUrl, iE, Sock)) {
      if (!GetHTTP09(iUrl, iE, Sock)) {
	return 0;
      } else return 1;
    }
    else return 1;
}
Ejemplo n.º 7
0
/////////////////////////////////////Constructeur////////////////////////////////////
Table::Table(int maxJ, int miseDep){
  //Partie constructeur reseau
  brPub = Sock(SOCK_STREAM, (short)21346,0);
  if(brPub.good())
    descTable = brPub.getsDesc();
  else{
    cout<<"Probleme desc"<<endl;
    exit(1);
  }
  if(listen(descTable,10) == -1){
    cout<<"erreur de creation Boite Publique"<<endl;
  }
  isServeur=false;
  descMax=descTable;
  //Partie constructeur des joueurs
  nbJoueur=0;
  nbJMax = maxJ;
  joueurEnListe=0;
  nbJAllIn=0;
  prochainAMiser=0;
  dernierAMiser=0;
  joueurs=new Joueur*[nbJMax];
  for(int i=0;i<nbJMax;i++){
    joueurs[i]=NULL;
  }
  actif=new bool[nbJMax];
  for(int i=0;i<nbJMax;i++){
    actif[i]=false;
  }
  //Partie constructeur poker
  partieEnCours=false;
  dealer=0;
  aJouer=false;
  miseMin = miseDep;
  mise = miseMin;
  pot = 0;
  instanceAllIn=false;
  
}
Ejemplo n.º 8
0
int main(int argc, char** argv)
{
    //获取程序启动参数
    int optch = 0;
    static char optstring[] = "o:l:s:vi:t:p:k:";
    extern char *optarg;

    char smode[128] = { 0 };
    int mode = -1;
    while ((optch = getopt(argc, argv, optstring)) != -1)
    {
        switch (optch)
        {
        case 'o'://启动模式
            strcpy(smode, optarg);
            if (strcmp(optarg, "rqueue") == 0)
                mode = 0;
            if (strcmp(optarg, "wqueue") == 0)
                mode = 1;
            if (strcmp(optarg, "queue") == 0)
                mode = 10;
            if (strcmp(optarg, "rsem") == 0)
                mode = 2;
            if (strcmp(optarg, "wsem") == 0)
                mode = 3;
            if (strcmp(optarg, "sem") == 0)
                mode = 11;
            if (strcmp(optarg, "rfifo") == 0)
                mode = 4;
            if (strcmp(optarg, "wfifo") == 0)
                mode = 5;
            if (strcmp(optarg, "fifo") == 0)
                mode = 12;
            if (strcmp(optarg, "rsock") == 0)
                mode = 6;
            if (strcmp(optarg, "wsock") == 0)
                mode = 7;
            if (strcmp(optarg, "sock") == 0)
                mode = 13;
            if (strcmp(optarg, "rusock") == 0)
                mode = 8;
            if (strcmp(optarg, "wusock") == 0)
                mode = 9;
            if (strcmp(optarg, "usock") == 0)
                mode = 14;
            if (strcmp(optarg, "rpoll") == 0)
                mode = 15;
            if (strcmp(optarg, "rpoll2") == 0)
                mode = 16;
            if (strcmp(optarg, "rpollset") == 0)
                mode = 17;
#ifdef OCE_CACHE
            if (strcmp(optarg, "rcache") == 0)
                mode = 18;
            if (strcmp(optarg, "wcache") == 0)
                mode = 19;
            if (strcmp(optarg, "cache") == 0)
                mode = 20;
#endif
            break;
        case 'l':
            g_len = atoi(optarg);
            break;
        case 's':
            g_usleep = atoi(optarg);
            break;
        case 'v':
            g_verify = 1;
            break;
        case 'i':
            strcpy(g_ip, optarg);
            break;
        case 't':
            loop_times = atol(optarg);
            break;
        case 'p':
            g_port = atol(optarg);
            break;
        case 'k':
            strcpy(g_sKeyFile, optarg);
            break;
        default:
            exit(-1);
        }
    }

    daemon();

    if(g_verify == 1)
    {
        memcpy(wbuff+sizeof(struct timeval), &g_data, sizeof(g_data));
        g_len = sizeof(struct timeval) + sizeof(g_data);
    }
    else
    {
        for (int i = 0; i < sizeof(wbuff); i++)
        {
            wbuff[i] = 'b';
        }
        wbuff[0] = 'a';
        wbuff[g_len-1] = 'a';
        wbuff[sizeof(wbuff) - 1] = '\0';
    }

    g_nSig = _RegisterSignal();
    if(g_nSig == NULL)
    {
        printf("Could not set up signal handling.  Aborting.\n");
        return -1;
    }

    if (mode == 0)
    {
        Rqueue();
    }
    if (mode == 1)
    {
        Wqueue();
    }
    if (mode == 2)
    {
        Rsem();
    }
    if (mode == 3)
    {
        Wsem();
    }
    if (mode == 4)
    {
        Rfifo();
    }
    if (mode == 5)
    {
        Wfifo();
    }
    if (mode == 6)
    {
        Rsock();
    }
    if (mode == 7)
    {
        Wsock();
    }
    if (mode == 8)
    {
        Rusock();
    }
    if (mode == 9)
    {
        Wusock();
    }
    if (mode == 10)
    {
        Queue();
    }
    if (mode == 11)
    {
        Sem();
    }
    if (mode == 12)
    {
        Fifo();
    }
    if (mode == 13)
    {
        Sock();
    }
    if (mode == 14)
    {
        Usock();
    }
    if (mode == 15)
    {
        Rpoll();
    }
    if (mode == 16)
    {
        Rpoll2();
    }
    if (mode == 17)
    {
        Rpollset();
    }
#ifdef OCE_CACHE
    if (mode == 18)
    {
        Rcache();
    }
    if (mode == 19)
    {
        Wcache();
    }
    if (mode == 20)
    {
        Cache_();
    }
#endif

    if(total_time0 != 0)
    {
        double avg1 = (double) total_time0 / (double) g_count0;
        double avg2 = (double) g_count0 / (double)((double) total_time0 / 1000000);
        printf("%s total0 g_count0:%lld, avgage %lf us, max %lf num/s\n", smode, g_count0, avg1,avg2);
    }
    if(recv_delay0 != 0)
    {
        double avg1 = (double) recv_delay0 / (double) recv_delay_count0;
        printf("%s recv delay avgage %lf us , max delay %llu\n", smode, avg1, g_delay_max);
    }
    if(total_time1 != 0)
    {
        double avg1 = (double) total_time1 / (double) g_count1;
        double avg2 = (double) g_count1 / (double)((double) total_time1 / 1000000);
        printf("%s total1 g_count1:%lld, avgage %lf us, max %lf num/s\n", smode, g_count1, avg1,avg2);
    }
    if(total_time2 != 0)
    {
        double avg1 = (double) total_time2 / (double) g_count2;
        double avg2 = (double) g_count2 / (double)((double) total_time2 / 1000000);
        printf("%s total2 g_count2:%lld, avgage %lf us, max %lf num/s\n", smode, g_count2, avg1,avg2);
    }

    printf("exit.\n");
    return 0;
}