Ejemplo n.º 1
0
void client(int sk) {
	int msg_size;
	int i;

	for (i = 0; i < msg_cnt; i++) {
		msg_size = next_msg_size(i);
		order_state = next_order(order_state, order_pattern);
		stream_state = next_stream(stream_state, stream_pattern);

		if (send_r(sk, stream_state, order_state, msg_size, 0) < 0) {
			close(sk);
			break;
		}

		/* The sender is echoing so do discard the echoed data. */
		if (drain && ((i + 1) % period == 0)) {
			receive_r(sk);
		}
	}
} /* client() */
Ejemplo n.º 2
0
void
mixed_mode_test(void)
{
	int error, i, j, max_fd, sks, size;
	int assoc_i, n_msg_size, n_order, n_stream;
	int done = 0;
	fd_set *ibitsp = NULL, *obitsp = NULL, *xbitsp = NULL;
        char incmsg[CMSG_SPACE(sizeof(_sctp_cmsg_data_t))];
        struct iovec iov;
        struct msghdr inmessage;
	_assoc_state *as;

	
	/* Set up the listeners.  If listeners is 0, set up one socket for
	 * transmitting only.
	 */
	iov.iov_base = NULL;
	max_fd = -1;
	sks = (0 == listeners) ? 1 : listeners;
	memset(poll_sks, 0, sizeof(sks * sizeof(_poll_sks)));

	for (i = 0; i < sks; i++) {
		poll_sks[i].sk = socket_r();

		if (s_loc.ss_family == AF_INET6)
			( (struct sockaddr_in6 *)&s_loc)->sin6_port =
				htons(local_port + i);
		else
			( (struct sockaddr_in *)&s_loc)->sin_port =
				htons(local_port + i);

		bind_r(poll_sks[i].sk, &s_loc);
		if (listeners) {
			listen_r(poll_sks[i].sk, 100);
		}
		if (max_msgsize > DEFAULT_MAX_WINDOW) {
			if (setsockopt(poll_sks[i].sk, SOL_SOCKET, SO_RCVBUF,
				&max_msgsize, sizeof(max_msgsize)) < 0) {
				perror("setsockopt(SO_RCVBUF)");
				exit(1);
			}
		} 	

		if (tosend) {
			if ((poll_sks[i].assoc_state = (_assoc_state *)malloc(
				sizeof(_assoc_state) * tosend)) == NULL) {
				printf("Can't allocate memory.\n");
				goto clean_up;
			}
			memset(poll_sks[i].assoc_state, 0,
				sizeof(_assoc_state) * tosend);
		}

		if (poll_sks[i].sk > max_fd) {
			max_fd = poll_sks[i].sk;
		}
	}

	size = howmany(max_fd + 1, NFDBITS) * sizeof(fd_mask);
	if ((ibitsp = (fd_set *)malloc(size)) == NULL) {
		printf("Can't allocate memory.\n");
		goto clean_up;
	}
	if ((obitsp = (fd_set *)malloc(size)) == NULL) {
		printf("Can't allocate memory.\n");
		goto clean_up;
	}
	if ((xbitsp = (fd_set *)malloc(size)) == NULL) {
		printf("Can't allocate memory.\n");
		goto clean_up;
	}

	memset(ibitsp, 0, size);
	memset(obitsp, 0, size);
	memset(xbitsp, 0, size);


        /* Initialize inmessage with enough space for DATA... */
        memset(&inmessage, 0, sizeof(inmessage));
        if ((iov.iov_base = malloc(REALLY_BIG)) == NULL) {
		fprintf(stderr, "\n\t\t*** malloc not enough memory!!! ***\n");
		goto clean_up;
	}
	iov.iov_len = REALLY_BIG;
	inmessage.msg_iov = &iov;
	inmessage.msg_iovlen = 1;
	/* or a control message.  */
	inmessage.msg_control = incmsg;
	inmessage.msg_controllen = sizeof(incmsg);

	/* Set up the remote port number per association for output.  */
	for (i = 0; i < sks; i++) {
		as = poll_sks[i].assoc_state;
		for (j = 0; j < tosend; j++) {
			as[j].rem_port = remote_port + j;
		}
	}

	while (!done) {

		for (i = 0; i < sks; i++) {
			FD_SET(poll_sks[i].sk, ibitsp);
			FD_SET(poll_sks[i].sk, obitsp);
			FD_SET(poll_sks[i].sk, xbitsp);
		}
		if ((error = select(max_fd + 1, ibitsp, obitsp, xbitsp,
			(struct timeval *)0)) < 0) {
			fprintf(stderr, "\n\t\t*** select() failed ");
			fprintf(stderr, "with error: %s\n\n",
				strerror(errno));
			fflush(stdout);
			goto clean_up;
		}
		
		for (i = 0; i < sks; i++) {
			/* Is there anything to read from the socket?  */
			if (listeners && FD_ISSET(poll_sks[i].sk, ibitsp)) {

				FD_CLR(poll_sks[i].sk, ibitsp);
				error = recvmsg(poll_sks[i].sk, &inmessage,
					MSG_WAITALL);
				if (error < 0) {
					fprintf(stderr,
						"\n\t\t*** recvmsg: %s ***\n\n",
						strerror(errno));
					fflush(stdout);
					goto clean_up;
				}
				else if (error == 0) {
					printf("\n\t\trecvmsg() returned ");
				       	printf("0 !!!!\n");
					fflush(stdout);
				}

				print_message(poll_sks[i].sk, &inmessage,
					error);

				inmessage.msg_control = incmsg;
				inmessage.msg_controllen = sizeof(incmsg);
				iov.iov_len = REALLY_BIG;
			}
			
			/* Is this socket writeable?  */
			if (tosend && FD_ISSET(poll_sks[i].sk, obitsp)) {

				FD_CLR(poll_sks[i].sk, obitsp);

				/* Pick an association.  */
				assoc_i = next_assoc(i, poll_sks[i].assoc_i,
						assoc_pattern);
				if (assoc_i < 0) {
					/* No work to do on any associations.
					 * We are probably done. */
					if (!listeners) {
						done = 1;
					}
					continue;
				}
				poll_sks[i].assoc_i = assoc_i;

				as = poll_sks[i].assoc_state;
				n_msg_size = next_msg_size(as[assoc_i].msg_cnt);
				n_order = as[assoc_i].order_state =
					next_order(as[assoc_i].order_state,
					order_pattern);
				n_stream = as[assoc_i].stream_state =
					next_stream(as[assoc_i].stream_state,
					stream_pattern);

				/* Set the destination port.  */
				if (s_rem.ss_family == AF_INET6)
					( (struct sockaddr_in6 *)&s_rem)->
						sin6_port =
						htons(as[assoc_i].rem_port);
				else
					( (struct sockaddr_in *)&s_rem)->
						sin_port =
						htons(as[assoc_i].rem_port);

				/* Send a message thru the association.  */
				if (send_r(poll_sks[i].sk, n_stream, n_order,
					n_msg_size, assoc_i) < 0) {
					/* Don't increment counter if there
					 * is a problem of sending.
					 */
					continue;
				}

				/* Increment counters. */
				if (++as[assoc_i].msg_cnt >= MSG_CNT) {
					as[assoc_i].msg_cnt = 0;
				}
				if (++as[assoc_i].msg_sent >=
					repeat_count) {
					fprintf(stderr, "Association #%d in ",
						assoc_i);
					fprintf(stderr, "sk=%d has ",
						poll_sks[i].sk);
					fprintf(stderr, "completed %d msg as ",
						as[assoc_i].msg_sent);
					fprintf(stderr, "cycle %d.\n",
						++as[assoc_i].cycle);

					/* In the mixed mode, -x not only
					 * specify the longer repeat cycle,
					 * but it also mean to run the test
					 * forever.
					 */
					if (xflag) {
						as[assoc_i].msg_sent = 0;
					}

				}

			}
		}
	}

clean_up:
	for (i = 0; i < sks; i++) {
		close(poll_sks[i].sk);
		if (poll_sks[i].assoc_state) {
			free(poll_sks[i].assoc_state);
		}
	}

	if (ibitsp) free(ibitsp);
	if (obitsp) free(obitsp);
	if (xbitsp) free(xbitsp);

	if (iov.iov_base) free(iov.iov_base);

} /* mixed_mode_test() */
Ejemplo n.º 3
0
// ------------------------------------------------------------------------------------------------
//
//
void PatternDisplay::disp_playing_pattern(Drawable *S) 
{
  int cy, rows, cur_row, pat, last ;
  int next ;
  TColor bg;
  

  //int dontchangeitasshole = 0
  
  last = 0;
  next = next_order();

  this->disp_row = cur_row = ztPlayer->playing_cur_row;

  rows = ysize / 2 ;
  cur_row -= rows;
  pat = ztPlayer->playing_cur_pattern;
  
  for (cy = y; cy<y+ysize; cy++) {
    
    if (cur_row < 0) {
      
      pat = ztPlayer->last_pattern;
      last = 1;
      
      if (pat<0) pat = ztPlayer->playing_cur_pattern;
      cur_row = song->patterns[pat]->length + cur_row ;
      }
     /* else
       if (!dontchangeitasshole)
       pat = ztPlayer->playing_cur_pattern;
    */

    if (cur_row >= song->patterns[pat]->length) {

      if (ztPlayer->playmode) {

        //dontchangeitasshole = 1;

        if (last) {

          pat = ztPlayer->playing_cur_pattern;
          last = 0;
        } 
        else {

          pat = next;
        }
      }
      
      cur_row = 0;
    }

    if (cur_row == this->disp_row) bg = COLORS.EditBGhigh;
    else bg = COLORS.EditBG;

    this->disp_playing_row(x,cy,pat,cur_row++,S,bg);
  }
  
  this->disp_track_headers(S);    
}