Exemple #1
0
int main(int argc, char *argv[]) {
	int status;
	int mode=0;
	pthread_t midiinthread;
	snd_rawmidi_t* midiin=NULL;
	const char* portname="hw:1,0,0";// see alsarawportlist.c example program
	if ((argc > 1) && (strncmp("hw:", argv[1], 3)==0)) {
		portname=argv[1];
	}
	if ((status=snd_rawmidi_open(&midiin, NULL, portname, mode)) < 0) {
		errormessage("Problem opening MIDI input: %s", snd_strerror(status));
		exit(EXIT_FAILURE);
	}
	// type "man pthread_create" for more information about this function:
	status=pthread_create(&midiinthread, NULL, midiinfunction, midiin);
	if (status==-1) {
		errormessage("Unable to create MIDI input thread.");
		exit(EXIT_FAILURE);
	}
	CHECK_ZERO(sleep(60));	// do nothing for a while; thread does all the work.
	snd_rawmidi_close(midiin);
	midiin=NULL;	// snd_rawmidi_close() does not clear invalid pointer,
	printf("\n");	// so might be a good idea to erase it after closing.
	return EXIT_SUCCESS;
}
Exemple #2
0
int MidiInit(void *arg)
{
	int status;
	int mode = SND_RAWMIDI_SYNC;
	char *portname = arg;
	midi.midiin = NULL;
	midi.midiout = NULL;
	char resetPad[3] = {0xB0, 0x00, 0x00};
	char setDrumMapping[3] = {0xB0, 0x00, 0x02};	// configure drum rack layout

	// open in/out
	if ((status = snd_rawmidi_open(&(midi.midiin), &(midi.midiout), portname, mode)) < 0) {
		errormessage("Problem opening MIDI input: %s", snd_strerror(status));
		exit(1);
	}

	// reset launchpad (replace with generic reset)
	if ((status = snd_rawmidi_write(midi.midiout, resetPad, 3)) < 0) {
		errormessage("Problem writing to MIDI output: %s", snd_strerror(status));
		exit(1);
	}

	// reset launchpad (replace with generic reset)
	if ((status = snd_rawmidi_write(midi.midiout, setDrumMapping, 3)) < 0) {
		errormessage("Problem writing to MIDI output: %s", snd_strerror(status));
		exit(1);
	}

	return NULL;
}
Exemple #3
0
void writefile(char far *fname)
 {
char error[60];

int fhandle;
if (driveready() == TRUE)
{
	fhandle = open(fname, O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
                              S_IREAD | S_IWRITE);
	if (fhandle != -1)
	{
        if (write(fhandle,&status,sizeof(statustype)) < sizeof(statustype))
	errormessage("Disk access error\nDisk probably full");
	else
        strncpy(sys.lastfile,fname,15);
	close(fhandle);
	}
	else
	{
	sprintf(error,"Disk access error\n%s",sys_errlist[errno]);
	errormessage(error);
	}
} else errormessage("Drive not ready 11\nCheck hardware");
strncpy(filename,sys.lastfile,15);
}
Exemple #4
0
int do_wri(u8 * file){
	s8 ret,fd;
	u32 retlba ;
	u8 i=0;
	u32 ch;
	u8 buff[256] = {0};
	if (!check_for_args(WRI,1))return 1;
	fd = openf(file,O_RW);
	if ( fd == -1){
		retlba=NO_LBA;
		if (ERROR_NO == NO_DIR_FILE)
			retlba  = creatf(file , 064);
		if (retlba  == NO_LBA){
			vd_puts ( "COULD NOT OPEN OR CREATE THE DESTINATION FILE\n" );
				errormessage(geterror());
			closef(fd);
			fl_clean();
			return 0;
		}
		fd = openf(file,O_RW);
	}
	if(fd == -1){
		vd_puts("CANNOT OPEN THE FILE\n");
		errormessage(geterror());
		fl_clean();
		return 1;
	}
	while(1){
		ch=getche();
		if(ch == 1)
			break;
        if( ch == 13 || ch == 10){printf("\n"); ch = '\n';}
		if (i == 255){
			i=0;
			ret = writef(fd,buff,256);
			if(ret == -1){
				vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n");
				errormessage(geterror());
				unlinkf(file);
				fl_clean();
				return 1;
			}
		}
		buff[i++] = ch;
	}
	ret = writef(fd,buff,i);
	if(ret == -1){
		vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n");
		errormessage(geterror());
		unlinkf(file);
		fl_clean();
		return 1;
	}
	closef(fd);
	vd_puts(" \n");
	fl_clean();
	return 0;
}
Exemple #5
0
int do_list(u8 * dir){
	s8 fd,ret;
	struct fnode fn;
	int i;
	u8 size;
	struct dir_str dira[256];
    u8 full_name[132];// fullpath name  of child
	if (!check_for_args(LIST,1)) return 1;
	fd = opend(dir);
	if (fd == -1){
		vd_puts("CANNOT OPEN DIRECTORY:: ");vd_puts(dir);vd_puts("\n");
				errormessage(geterror());
				fl_clean();
		return 1;
	}
	ret = finfo(fd,&fn);
	if (ret == -1){
		vd_puts(" CANNOT OPEN DIRECTORY::");vd_puts(dir);vd_puts("\n");
		errormessage(geterror());
		fl_clean();
		return 1;
	}
	size = fn.ct_links;
	ret=readd(fd,size+2,dira);
	if (! ret){
		vd_puts(" CANNOT READ THE DIRECTORY\n");
				errormessage(geterror());
				fl_clean();
		return 2;
	}
	for(i=0; i < size+2 ; i++){
#ifdef COLOR_LIST 
        strcpy(full_name,dir);
        strcat(full_name,"|");
        strcat(full_name,dira[i].name);
        if ( !strcmp(dira[i].name,".") || ! strcmp(dira[i].name,"..") ){
            textcolor(YELLOW);
            cprintf("%s\n\r",dira[i].name);
            textcolor(WHITE);
            continue;
        }
        if ( is_dir(full_name) ){
            textcolor(YELLOW);
            cprintf("%s\n\r",dira[i].name);
            continue;
        }
        textcolor(BLUE);
        cprintf("%s\n\r",dira[i].name);
#else
        printf("%s\n",dira[i].name);
#endif
    }
    textcolor(WHITE);
    fl_clean();
	return 0;
}
Exemple #6
0
int do_app(u8 * file){
	s8 ret,fd;
	u8 i=0;
	u32 ch;
	u8 buff[256];
	struct fnode fn;
	u32 size;
	if (!check_for_args(APP,1)) return 1;
	fd = openf(file,O_RW);
	if(fd == -1){
		vd_puts( "CANNOT OPEN THE FILE\n");
				errormessage(geterror());
				fl_clean();
		return 1;
	}
	finfo(fd, & fn);
	size = fn.size;
	ret= seekf(fd,  size,SEEK_BEG);
	while(1){
		ch=getche();
		if(ch == 1)
			break;
        if (ch == 13 || ch == 10 ){
            printf("\n");ch='\n';
        }
		if (i == 255){
			i=0;
			ret = writef(fd,buff,256);
			if(ret == -1){
				vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n");
                errormessage(geterror());
				unlinkf(file);
                fl_clean();
				return 1;
			}
		}
		buff[i++] = (u8)ch;
	}
	ret = writef(fd,buff,i);
	if(ret == -1){
		vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n");
				errormessage(geterror());
		unlinkf(file);
				fl_clean();
		return 1;
	}
    puts(" ");
	closef(fd);
		fl_clean();
	return 0;

}
Exemple #7
0
void *midifunction(void *arg)
{
	// this is the parameter passed via last argument of pthread_create():
	struct midinodes *midi = (struct midinodes*)arg;
	char buffer[1];
	int  count = 0;
	int status;
	int byteNum = 0;
	char outBuffer[3] = {0x90, 0x00, 15};
	note currentNote;

	printf("midi thread start\n");

	while (1) {
		if ((status = snd_rawmidi_read(midi->midiin, buffer, 1)) < 0) {
			errormessage("Problem reading MIDI input: %s", snd_strerror(status));
		}
		count++;
		// determine part of message
		if(byteNum == 0)
		{
			// note
			outBuffer[1] = currentNote.key = buffer[0];
			byteNum = 1;
		}
		else
		{
			if(buffer[0] > 0)
				outBuffer[2] = currentNote.vel = NOTE_ON;
			else
				outBuffer[2] = currentNote.vel = NOTE_OFF;
			byteNum = 0;
		}
		// after velocity, write
		if(byteNum == 0)
		{
			if ((status = snd_rawmidi_write(midi->midiout, outBuffer, 3)) < 0) {
				errormessage("Problem writing to MIDI output: %s", snd_strerror(status));
				exit(1);
			}
			printf("Note: %d %d %d \n", outBuffer[0], currentNote.key, currentNote.vel);
			SynthNoteStart(currentNote);
		}
		fflush(stdout);
	}

	return NULL;
}
Exemple #8
0
int do_info(u8 * file){
	struct fnode fn;
	s8 ret;
	if (!check_for_args(FINFO,1)) return 1;
   ret = info(file, &fn);
   if(ret == -1){
		vd_puts("CANNOT GET INFO\n");
		errormessage(geterror());
		fl_clean();
		return 1;
   }

   vd_puts("File :"); vd_puts(file);vd_puts("\n");
   vd_puts("Size :"); vd_putint((unsigned int)fn.size);vd_puts("\n");
   vd_puts("Links :"); vd_putint((unsigned int)fn.ct_links);vd_puts("\n");
   vd_puts("m_time :");vd_putint((unsigned int)fn.m_time);vd_puts("\n");
   vd_puts("User id :" );vd_putint( (unsigned int)fn.uid );vd_puts("\n");
   vd_puts("mode :" ); vd_putint( (unsigned int)fn.mode );vd_puts("\n");
   (fn.mode & 0x80 )? vd_puts("DIRECTORY") : vd_puts("ORDINARY FILE" ) ;vd_puts("\n");
    vd_puts("PERMISSIONS :: \n" );
   (fn.mode & OWNER_READ)? vd_puts("r"):vd_puts("-") ;
   (fn.mode & OWNER_WRITE)?vd_puts("w"):vd_puts("-") ;
   (fn.mode & OWNER_EXECUTE)?vd_puts("x"):vd_puts("-");
   (fn.mode & OTHER_READ)?vd_puts("r"):vd_puts("-") ;
   (fn.mode & OTHER_WRITE)?vd_puts("w"):vd_puts("-") ;
   (fn.mode & OTHER_EXECUTE)?vd_puts("x"):vd_puts("-") ;vd_puts("\n");
   fl_clean();
   return 0;
}
Exemple #9
0
void CommandParser::do_cd(){
	int len;
	if (!is_loaded){
		vd_puts("FILE SYSTEM NOT LOADED\n");
		return ;
	}
	if(flpchange){
		uloadfs();
	}
	if ( strlen(first_arg) == 0){
		vd_puts("Current Dir:");
		vd_puts(curr_dir);
		return;
	}
    toAbsolute(first_arg);
	if ( ispresent(first_arg) == -1  ){
	   vd_puts( "THE DIRECTORY SEEMS TO BE ON A HOLIDAY !!\n" );
	   errormessage(geterror());
	   return;
	}
    if ( !is_dir(first_arg) ){
       vd_puts( "The Specified File is not a directory\n" );
	   return;
    }
    strcpy(curr_dir,first_arg);
}
Exemple #10
0
int do_adduser(){
    s8 ret;
	u32 i=0;
	u8 id;
	u8 password[PASSWORD_LENGTH] , ch;
	u8 username[MAX_NAME];
	if (!check_for_args(ADDUSER,0)) return 1;
	vd_puts("ENTER USER NAME ::" );
	gets(username);
	username[--i] = 0;
	i=0;
	vd_puts("\nENTER PASSWORD ::" );
	while (i <= PASSWORD_LENGTH && (ch = password[i++] = getch()) != (u8)('\n') && ch != (u8)('\r'))vd_putchar('#');
	password[--i] = 0;
	vd_puts("\n");
	ret=useradd(username,password);
	if (ret == -1) {
	   vd_puts("COULD NOT ADD USER\n");
	   errormessage(geterror());
	   fl_clean();
	   return 1;
	}
	fl_clean();
	return 0;
}
Exemple #11
0
int Socket::receive ( char* data, const unsigned int buffersize, const unsigned int minpacketsize ) const
{

  unsigned int receivedsize = 0;
  int status = 0;

  if ( !is_valid() )
  {
    return 0;
  }

  while ( (receivedsize <= minpacketsize) && (receivedsize < buffersize) )
  {
    status = ::recv(_sd, data+receivedsize, (buffersize - receivedsize), 0 );

    if ( status == SOCKET_ERROR )
    {
      errormessage( getLastError(), "Socket::receive" );
      return status;
    }

    receivedsize += status;
  }

  return receivedsize;
}
Exemple #12
0
bool Socket::create()
{
  if( is_valid() )
  {
    close();
  }

  if(!osInit())
  {
    return false;
  }

  _sd = socket(_family, _type, _protocol );
  //0 indicates that the default protocol for the type selected is to be used.
  //For example, IPPROTO_TCP is chosen for the protocol if the type  was set to
  //SOCK_STREAM and the address family is AF_INET.

  if (_sd == INVALID_SOCKET)
  {
    errormessage( getLastError(), "Socket::create" );
    return false;
  }

  return true;
}
Exemple #13
0
bool Socket::connect ( const std::string& host, const unsigned short port )
{
  if ( !is_valid() )
  {
    return false;
  }

  _sockaddr.sin_family = _family;
  _sockaddr.sin_port = htons ( port );

  if ( !setHostname( host ) )
  {
    XBMC->Log(LOG_ERROR, "Socket::setHostname(%s) failed.\n", host.c_str());
    return false;
  }

  int status = ::connect ( _sd, reinterpret_cast<sockaddr*>(&_sockaddr), sizeof ( _sockaddr ) );

  if ( status == SOCKET_ERROR )
  {
    XBMC->Log(LOG_ERROR, "Socket::connect %s:%u\n", host.c_str(), port);
    errormessage( getLastError(), "Socket::connect" );
    return false;
  }

  return true;
}
Exemple #14
0
void *midiinfunction(void *arg) {
	// this is the parameter passed via last argument of pthread_create():
	snd_rawmidi_t* midiin=(snd_rawmidi_t*)arg;
	char buffer[1];
	int count=0;
	int status;
	while (1) {
		if (midiin==NULL) {
			break;
		}
		if ((status=snd_rawmidi_read(midiin, buffer, 1)) < 0) {
			errormessage("Problem reading MIDI input: %s", snd_strerror(status));
		}
		count++;
		if ((unsigned char)buffer[0] >=0x80) {	// print command in hex
			printf("0x%x ", (unsigned char)buffer[0]);
		} else {
			printf("%d ", (unsigned char)buffer[0]);
		}
		fflush(stdout);
		if (count % 20==0) {
			printf("\n");
		}
	}
	return NULL;
}
Exemple #15
0
static double calcwidth12(void)
{ 
 int i,nsub;
 double width12 = 0.;
 double selChan=0;
 int first=1;
 
 long N1;

 err_code = 0; 

 for(nsub=1;nsub<=nprc_int;nsub++) widths[nsub-1]=0;
 for(nsub=1;nsub<=nprc_int;nsub++) 
 {  double m1, m2, m3;

    if(strcmp(pinf_int(nsub,1,&m1,&N1),inParticle)==0) 
    { 
      if(first)
      { 
        if(EffQmass&&Q) *Q=m1;
        if(calcFunc_int()>0)
        {  messanykey(15,15,"Can not  calculate constraints");
           return 0;
        } 
        if(GG)
        { if(SC) *GG=*SC; 
          else {if(Q) *GG=sqrt(4*M_PI*alpha_2(*Q)); else *GG=sqrt(4*M_PI*alpha_2(m1));}
        }

        first=0;
      }  
      pinf_int(nsub,1,&m1,NULL);pinf_int(nsub,2,&m2,NULL);pinf_int(nsub,3,&m3,NULL);
          
      if (m1 <=m2 + m3) widths[nsub-1] = 0.0; 
      else 
      { 
        double md=m2-m3;
        double ms=m2+m3; 
        double pRestOut=sqrt((m1*m1 - ms*ms)*(m1*m1-md*md))/(2*m1);
        double totcoef= pRestOut/(8. * M_PI * m1*m1);
                   
        for(i=1;i<12;i++) pvect[i]=0;
        pvect[0]=m1;
        pvect[7]=pRestOut;
        pvect[4]=sqrt(pRestOut*pRestOut+m2*m2);
        pvect[11]=-pRestOut;
        pvect[8]=sqrt(pRestOut*pRestOut+m3*m3);
            
        widths[nsub-1] = totcoef * sqme_int(nsub,pvect,&err_code);
        if(err_code != 0) {  errormessage(); widths[nsub-1]=0; err_code=0;}
        width12 += widths[nsub-1];
        if(nsubSel==nsub) selChan= widths[nsub-1];
      }
    }  
 }
 if(nsubSel) { if(width12) return selChan/width12; else return 0;}  
 return width12; 
} 
Exemple #16
0
int do_show(u8 * file){
	s8 fd, ret ; u32 i ;
	struct fnode fn;
	u32 size;
	u8 buff[1025];

	if (!check_for_args(SHOW,1)) return 1;
	fd=openf(file,O_READ);
	if ( fd == -1){
		vd_puts("CANNOT OPEN THE FILE\n");
				errormessage(geterror());
				fl_clean();
		return 1;
	}

	ret = finfo(fd,&fn);
	if ( ret == -1){
		vd_puts("CANNOT OPEN THE FILE\n");
				errormessage(geterror());
				fl_clean();
		return 1;
	}
	size=fn.size;
	while(size){
		ret = readf(fd,buff,(size < 1024 ? size : 1024));
		if ( ret == -1){
			vd_puts("CANNOT  READ THE FILE\n");
					errormessage(geterror());
					fl_clean();
			return 1;
		}
		buff[(size < 1024 ? size : 1024)]=0 ;
		for(i = 0 ; i < (size < 1024 ? size : 1024) ; ++i )
			if ( buff[i] == 10 || buff[i] == 13) buff[i] = '\n';
		vd_puts( buff);
		vd_puts("\n");
		if (size >= 1024)
		    size-=1024 ;
		else
			size=0;
	}
	closef(fd);
	fl_clean();
	return 0;
}
std::string ProtoMessage::getErrorMessage() const
{
	auto rspCode = m_protoMsg->mutable_rspcode();
	if (rspCode == nullptr)
	{
		return "";
	}
	return rspCode->errormessage();
}
Exemple #18
0
int do_rmd(u8 * dir){
	s8 ret;
	if (!check_for_args(RMD,1)) return 1;
	ret= removed(dir);
	if(ret == -1){
		vd_puts("CANNOT REMOVE THIS  DIRECTORY\n");
				errormessage(geterror());
		}
		fl_clean();
	return 0;
}
Exemple #19
0
int do_rf(u8 * file){
	s8 ret;
	if (!check_for_args(RF,1)) return 1;
	ret = unlinkf(file);
	if(ret == -1){
		vd_puts("CANNOT REMOVE THE FILE\n");
				errormessage(geterror());
		}
	fl_clean();
	return 0;
}
Exemple #20
0
int do_ren(u8 * _old , u8 * _new){
	s8 ret;
	if (!check_for_args(REN,2)) return 1;
	ret =ren(_old, _new);
	if(ret == -1){
		vd_puts("CANNOT RENAME THIS FILE\n");
		errormessage(geterror());
	}
	fl_clean();
	return 0;
}
Exemple #21
0
int do_link(u8 * file , u8 * link){
	s8 ret;
	if (!check_for_args(LINK,2)) return 1;
	ret = linkf(file,link);
	if(ret == -1){
		vd_puts("CANNOT CREATE LINK\n");
				errormessage(geterror());
		}
		fl_clean();
	return 0;
}
Exemple #22
0
void echomidi(snd_rawmidi_t* midiin, snd_rawmidi_t* midiout) {
	unsigned char readbuffer;	// storage for input MIDI byte stream
	unsigned char buffer[1024]={0};	// storage space for incoming commands
	int dataptr=0;	// writing index in buffer
	int argsLeft=0;	// bytes left to read for a command
	int transpose=6;// transposition for note out
	int newnote;	// temp storage for output note
	int status;	// storage for error codes
	while(true) {
		if ((status=snd_rawmidi_read(midiin, &readbuffer, 1)) < 0) {
			errormessage("Problem reading MIDI input: %s", snd_strerror(status));
		}
		if (readbuffer & 0x80) {// a command byte has arrived
			argsLeft=getArgsExpected(readbuffer);
			dataptr=0;
			buffer[dataptr++]=readbuffer;
		} else {// a data byte has arrived
			if ((dataptr==0) || (argsLeft <=0)) {
				argsLeft=getArgsExpected(buffer[0]);
				dataptr=1;
			}
			buffer[dataptr++]=readbuffer;
			argsLeft--;
		}
		if ((argsLeft==0) && (((buffer[0] & 0xf0)==0x90) || ((buffer[0] & 0xf0)==0x80))) {
			newnote=buffer[1] + transpose;
			if ((newnote > 0) && (newnote < 128)) {
				buffer[1]=(unsigned char)newnote;
				if ((status=snd_rawmidi_write(midiout, buffer, 3)) < 0) {
					errormessage("Problem with MIDI out: %s", snd_strerror(status));
					exit(EXIT_FAILURE);
				} else if (((buffer[0] & 0xf0)==0x90) && ((buffer[2] & 0x0f)!=0)) {
					printf("New note: %d\n", newnote);
				}
			}
		}
		if (dataptr > 1000) {
			dataptr=0;
		}
	}
}
Exemple #23
0
int MidiStartProc(void *arg)
{
	int status;

	// type "man pthread_create" for more information about this function:
	status = pthread_create(&midithread, NULL, midifunction, &midi);
	if (status == -1) {
		errormessage("Unable to create MIDI input thread.");
		exit(1);
	}
	return NULL;
}
Exemple #24
0
int do_chperm(u8 * path , u8 * newperm){
		s8 ret;
		u8 own;
    if (!check_for_args(CHPERM,1)) return 1;
		own = (u8)atoi((char *)newperm);
		ret = chperm(path,own);
		if (ret == -1){
				vd_puts ( "COULD NOT CHANGE PERMISSION\n");
				errormessage(geterror());
		}
		fl_clean();
		return 0;
}
Exemple #25
0
int do_mkd(u8 * dir){
	s8 ret;
	u32 retlba;
	if (!check_for_args(MKD,1)) return 1;
	vd_puts(dir);
	vd_puts("\n");
	retlba  = maked(dir);
	if(retlba == NO_LBA){
		vd_puts( "CANNOT MAKE DIRECTORY\n"  );
				errormessage(geterror());
		}
		 fl_clean();
	return 0;
}
Exemple #26
0
int do_chown(u8 * path , u8 * newown){
		s8 ret;
		if (! is_loaded){
				vd_puts( "FILE SYSTEM NOT LOADED\n" );
				return 0;
		}
		ret = chown(path,newown);
		if (ret == -1){
				vd_puts("COULD NOT CHANGO OWNERSHIP\n") ;
				errormessage(geterror());
		}
		fl_clean();
		return 0;
}
Exemple #27
0
int Socket::receive ( char* data, const unsigned int buffersize, const unsigned int minpacketsize ) const
{

  unsigned int receivedsize = 0;
  int status = 0;

  if ( !is_valid() )
  {
    return 0;
  }

  while ( (receivedsize <= minpacketsize) && (receivedsize < buffersize) )
  {
    status = ::recv(_sd, data+receivedsize, (buffersize - receivedsize), 0 );

    if ( status == SOCKET_ERROR )
    {
      int lasterror = getLastError();
#if defined(TARGET_WINDOWS)
      if ( lasterror != WSAEWOULDBLOCK)
        errormessage( lasterror, "Socket::receive" );
#else
      if ( lasterror != EAGAIN && lasterror != EWOULDBLOCK )
        errormessage( lasterror, "Socket::receive" );
#endif
      return status;
    }

    receivedsize += status;

	if (receivedsize >= minpacketsize)
		break;
  }

  return receivedsize;
}
int Socket::send ( const char* data, const unsigned int len )
{
  fd_set set_w, set_e;
  struct timeval tv;
  int  result;

  if (!is_valid())
  {
    return 0;
  }

  // fill with new data
  tv.tv_sec  = 0;
  tv.tv_usec = 0;

  FD_ZERO(&set_w);
  FD_ZERO(&set_e);
  FD_SET(_sd, &set_w);
  FD_SET(_sd, &set_e);

  result = select(FD_SETSIZE, &set_w, NULL, &set_e, &tv);

  if (result < 0)
  {
    KODI->Log(LOG_ERROR, "Socket::send  - select failed");
    close();
    return 0;
  }
  if (FD_ISSET(_sd, &set_w))
  {
    KODI->Log(LOG_ERROR, "Socket::send  - failed to send data");
    close();
    return 0;
  }

  int status = ::send(_sd, data, len, 0 );

  if (status == -1)
  {
    errormessage( getLastError(), "Socket::send");
    KODI->Log(LOG_ERROR, "Socket::send  - failed to send data");
    close();
    return 0;
  }
  return status;
}
Exemple #29
0
bool Socket::accept ( Socket& new_socket ) const
{
  if (!is_valid())
  {
    return false;
  }

  socklen_t addr_length = sizeof( _sockaddr );
  new_socket._sd = ::accept(_sd, const_cast<sockaddr*>( (const sockaddr*) &_sockaddr), &addr_length );

  if (new_socket._sd <= 0)
  {
    errormessage( getLastError(), "Socket::accept" );
    return false;
  }

  return true;
}
Exemple #30
0
bool Socket::setHostname ( const std::string& host )
{
  if (isalpha(host.c_str()[0]))
  {
    // host address is a name
    struct hostent *he = NULL;
    if ((he = gethostbyname( host.c_str() )) == 0)
    {
      errormessage( getLastError(), "Socket::setHostname");
      return false;
    }

    _sockaddr.sin_addr = *((in_addr *) he->h_addr);
  }
  else
  {
    _sockaddr.sin_addr.s_addr = inet_addr(host.c_str());
  }
  return true;
}