Esempio n. 1
0
/*----------------------------------------------------------------------*
                             rtp_term_aux_putc
 *----------------------------------------------------------------------*/
void rtp_term_aux_putc (char ch)
{
    HANDLE hComm;
    OVERLAPPED osWrite = {0};
    unsigned long bytesWritten;
    unsigned long error;

    hComm = (HANDLE) auxComm;

    // Create this write operation's OVERLAPPED structure's hEvent.
    osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (osWrite.hEvent == NULL)
    {
        rtp_term_puts("rtp_term_aux_putc: error creating overlapped event handle\n");
        return;
    }
    if (WriteFile( hComm, &ch, 1, &bytesWritten, &osWrite) == 0)
    {
        if ((error = GetLastError()) != ERROR_IO_PENDING) 
        { 
            char test[100];
            rtp_sprintf(test, "rtp_term_aux_putc: Error in Write! %d\n", error);
            rtp_term_puts(test);    
            // WriteFile failed, but it isn't delayed. Report error and abort.
        }
        else 
        {
            // Write is pending.
            GetOverlappedResult(hComm, &osWrite, &bytesWritten, TRUE);
        }
    }
    CloseHandle(osWrite.hEvent);
}
Esempio n. 2
0
/*----------------------------------------------------------------------*
                              rtp_file_lseek
 *----------------------------------------------------------------------*/
long rtp_file_lseek (RTP_HANDLE fd, long offset, int origin)
{
long result;
int  relative_to;

#ifdef RTP_DISPLAY_ERROR
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif

    switch (origin)
    {
        case 0:
            relative_to = SEEK_SET;
            break;
        case 1:
            relative_to = SEEK_CUR;
            break;
        case 2:
            relative_to = SEEK_END;
            break;
        default:
#ifdef RTP_DISPLAY_ERROR
            errno = PEINVALIDPARMS;
            result = errno;
            rtp_term_cputs("rtp_file_lseek: error returned ");
            rtp_term_puts(rtp_itoa(result, error, 10));
#endif
            return (-1);
            break;
    }

    if ((result = (long) lseek ((int) fd, offset, relative_to)) < 0)
    {
#ifdef RTP_DISPLAY_ERROR
        result = errno;
        rtp_term_cputs("rtp_file_lseek: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }
    return (result);
}
Esempio n. 3
0
/*----------------------------------------------------------------------*
                           rtp_file_chmode
 *----------------------------------------------------------------------*/
int rtp_file_chmode (char * name, unsigned char attributes)
{
int ertfsmode;

#ifdef RTP_DISPLAY_ERROR
    int result;
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif

    ertfsmode  = 0;
    ertfsmode |= (attributes & RTP_FILE_ATTRIB_RDONLY)  ?  ARDONLY : 0;
    ertfsmode |= (attributes & RTP_FILE_ATTRIB_ARCHIVE) ?  ARCHIVE : 0;
    ertfsmode |= (attributes & RTP_FILE_ATTRIB_HIDDEN)  ?  AHIDDEN : 0;
    ertfsmode |= (attributes & RTP_FILE_ATTRIB_SYSTEM)  ?  ASYSTEM : 0;
    
    if (!pc_set_attributes ((const char *)name, ertfsmode))
    {
#ifdef RTP_DISPLAY_ERROR
        result = errno;
        rtp_term_cputs("rtp_file_chmode: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }
    return (0);
}
Esempio n. 4
0
/*----------------------------------------------------------------------*
                           rtp_file_get_attrib
 *----------------------------------------------------------------------*/
int rtp_file_get_attrib (void * dirobj, unsigned char * attributes)
{    
#ifdef RTP_DISPLAY_ERROR
    int  result;
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif

    if (!dirobj)
    {
#ifdef RTP_DISPLAY_ERROR
        errno = PEINVALIDPARMS;
        result = errno;
        rtp_term_cputs("rtp_file_get_attrib: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }

    *attributes  = (((DSTAT *)dirobj)->fattribute & ADIRENT) ? RTP_FILE_ATTRIB_ISDIR   : 0;
    *attributes |= (((DSTAT *)dirobj)->fattribute & ARDONLY) ? RTP_FILE_ATTRIB_RDONLY  : RTP_FILE_ATTRIB_RDWR;
    *attributes |= (((DSTAT *)dirobj)->fattribute & ARCHIVE) ? RTP_FILE_ATTRIB_ARCHIVE : 0;
    *attributes |= (((DSTAT *)dirobj)->fattribute & AHIDDEN) ? RTP_FILE_ATTRIB_HIDDEN  : 0;
    *attributes |= (((DSTAT *)dirobj)->fattribute & ASYSTEM) ? RTP_FILE_ATTRIB_SYSTEM  : 0;
    *attributes |= (((DSTAT *)dirobj)->fattribute & AVOLUME) ? RTP_FILE_ATTRIB_ISVOL   : 0;
    
    return (0);
}
Esempio n. 5
0
/*----------------------------------------------------------------------*
                            rtp_file_get_size
 *----------------------------------------------------------------------*/
int rtp_file_get_size (void * dirobj, unsigned long * size)
{
#ifdef RTP_DISPLAY_ERROR
    int  result;
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif

    if (!dirobj)
    {
#ifdef RTP_DISPLAY_ERROR
        errno = PEINVALIDPARMS;
        result = errno;
        rtp_term_cputs("rtp_file_get_size: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }
    
    *size = ((DSTAT *)dirobj)->fsize;
    return (0);
}
Esempio n. 6
0
/*----------------------------------------------------------------------*
                             rtp_file_gnext
 *----------------------------------------------------------------------*/
int rtp_file_gnext (void * dirobj)
{
#ifdef RTP_DISPLAY_ERROR
    int result;
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif

    if (!pc_gnext ((DSTAT *)dirobj))
    {
#ifdef RTP_DISPLAY_ERROR
        result = errno;
        rtp_term_cputs("rtp_file_gnext: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }

    return (0);
}
Esempio n. 7
0
/*----------------------------------------------------------------------*
                             rtp_file_pwd
 *----------------------------------------------------------------------*/
int rtp_file_pwd (char * name, long size)
{
	char drv_name[10];
	int drive;

#ifdef RTP_DISPLAY_ERROR
    int result;
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif

	drive = pc_getdfltdrvno();		/* get the current drive */
	sprintf(drv_name,"%c:", drive + 'A');
    if (!pc_pwd (drv_name, name))
    {
#ifdef RTP_DISPLAY_ERROR
        result = errno;
        rtp_term_cputs("rtp_file_pwd: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }
    
    return (0);
}
Esempio n. 8
0
/*----------------------------------------------------------------------*
                              rtp_file_write
 *----------------------------------------------------------------------*/
long rtp_file_write (RTP_HANDLE fileHandle, const unsigned char * buffer, long count)
{
int result;
    
#ifdef RTP_DISPLAY_ERROR
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif

    if ((result = write ((int) fileHandle, buffer, (int) count)) < 0)
    {
#ifdef RTP_DISPLAY_ERROR
        result = errno;
        rtp_term_cputs("rtp_file_write: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }
    return (result);
}
Esempio n. 9
0
/*----------------------------------------------------------------------*
                             rtp_file_gfirst
 *----------------------------------------------------------------------*/
int rtp_file_gfirst (void ** dirobj, char * name)
{
DSTAT fdata;

#ifdef RTP_DISPLAY_ERROR
    int result;
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif
    
    if (!pc_gfirst (&fdata, name))
    {
#ifdef RTP_DISPLAY_ERROR
        result = errno;
        rtp_term_cputs("rtp_file_gfirst: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }
    
    *dirobj = (void *)fdata;
    return (0);
}
Esempio n. 10
0
/*----------------------------------------------------------------------*
                               rtp_file_open
 *----------------------------------------------------------------------*/
int rtp_file_open (RTP_HANDLE  * fdPtr, const char * name, unsigned short flag, unsigned short mode)
{
PCFD fileHandle;
int result;

#ifdef RTP_DISPLAY_ERROR
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif

    fileHandle = open (name, _rtp_flag_to_operation(flag), _rtp_mode_to_permission(mode));

    if (fileHandle == (PCFD)(-1))
    {
        result = errno;
        /* ----------------------------------- */
        /*  If trying to open a directory or   */
        /*  opening a read only file with      */
        /*  write privilages.  This can be     */
        /*  non-fatal if doing an open to      */
        /*  determine the existance of a       */
        /*  directory.                         */
        /* ----------------------------------- */
        if (result == PEACCES)
        {
#ifdef RTP_DISPLAY_ERROR
            rtp_term_cputs("rtp_file_open: non-fatal error returned ");
            rtp_term_puts(rtp_ltoa(result, error, 10));
#endif
            return (-2);
        }
#ifdef RTP_DISPLAY_ERROR
        rtp_term_cputs("rtp_file_open: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }
    *fdPtr = (RTP_HANDLE) fileHandle;
    return (0);
}
Esempio n. 11
0
/*----------------------------------------------------------------------*
                           rtp_file_get_name
 *----------------------------------------------------------------------*/
int rtp_file_get_name (void * dirobj, char * name, int size)
{
unsigned int sizelimit;
    
#ifdef RTP_DISPLAY_ERROR
    int  result;
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif

    if (!dirobj)
    {
#ifdef RTP_DISPLAY_ERROR
        errno = PEINVALIDPARMS;
        result = errno;
        rtp_term_cputs("rtp_file_get_name: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }

#if (VFAT)
    sizelimit = strlen(((DSTAT *)dirobj)->lfname);
    if (sizelimit > size)
    {
        sizelimit = size;
    }
    strncpy (name, (const char *) (((DSTAT *)dirobj)->lfname), sizelimit);
#else
    sizelimit = strlen(((DSTAT *)dirobj)->filename);
    if (sizelimit > size)
    {
        sizelimit = size;
    }
    strncpy (name, (const char *) (((DSTAT *)dirobj)->filename), sizelimit);
#endif

    return (0);
}
Esempio n. 12
0
/*----------------------------------------------------------------------*
                             rtp_file_setcwd
 *----------------------------------------------------------------------*/
int rtp_file_setcwd (char * name)
{
#ifdef RTP_DISPLAY_ERROR
    int result;
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif

    if (!pc_set_cwd (name))
    {
#ifdef RTP_DISPLAY_ERROR
        result = errno;
        rtp_term_cputs("rtp_file_setcwd: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }
    return (0);
}
Esempio n. 13
0
/*----------------------------------------------------------------------*
                             rtp_file_flush
 *----------------------------------------------------------------------*/
int rtp_file_flush (RTP_HANDLE fd)
{
#ifdef RTP_DISPLAY_ERROR
    int result;
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif

    if (!flush_fd((int) fd))
    {
#ifdef RTP_DISPLAY_ERROR
        result = errno;
        rtp_term_cputs("rtp_file_flush: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }
    return (0);
}
Esempio n. 14
0
/*----------------------------------------------------------------------*
                              rtp_file_close
 *----------------------------------------------------------------------*/
int rtp_file_close (RTP_HANDLE fileHandle)
{
#ifdef RTP_DISPLAY_ERROR
    int result;
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif

    if (po_close ((PCFD) fileHandle) != 0)
    {
#ifdef RTP_DISPLAY_ERROR
        result = errno;
        rtp_term_cputs("rtp_file_close: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }
    return (0);
}
Esempio n. 15
0
/*----------------------------------------------------------------------*
                           rtp_file_get_free
 *----------------------------------------------------------------------*/
int rtp_file_get_free (char * name, unsigned long *total, unsigned long *free,
                       unsigned long *sectors_per_unit, unsigned short *bytes_per_sector)
{
dword total_blocks, free_blocks;
long bytes_free;
word size;

#ifdef RTP_DISPLAY_ERROR
    int result;
    char error[32];

    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    errno = 0;
#endif
    bytes_free = pc_lfree (name, &total_blocks, &free_blocks, &size, FALSE);
    
    if (bytes_free < 0)
    {
#ifdef RTP_DISPLAY_ERROR
        result = errno;
        rtp_term_cputs("rtp_file_get_free: error returned ");
        rtp_term_puts(rtp_itoa(result, error, 10));
#endif
        return (-1);
    }

    *total = (unsigned long) total_blocks;
    *free  = (unsigned long) free_blocks;
    *sectors_per_unit = (unsigned long) 1;
    *bytes_per_sector = (unsigned short) size;

    return (0);
}
Esempio n. 16
0
/* SPR - was RTP_HANDLE but didn't build */
long rtp_term_aux_open(void)
{
    HANDLE hComm;
    DCB dcb;

    /* JRT */
    COMMTIMEOUTS comm_timeouts;

    hComm = CreateFile( RTP_TERM_AUX_COMM_PORT,  
                    GENERIC_READ | GENERIC_WRITE, 
                    0, 
                    0, 
                    OPEN_EXISTING,
                    FILE_FLAG_OVERLAPPED,
                    0);
    if (hComm == INVALID_HANDLE_VALUE)
    {
        rtp_term_puts("Error in opening serial comm\n");
        return -1;
    }
    if (!GetCommState(hComm, &dcb))     // get current DCB
          // Error in GetCommState
          return FALSE;

    FillMemory(&dcb, sizeof(dcb), 0);
    dcb.DCBlength = sizeof(dcb);
    if (!BuildCommDCB("baud=9600 parity=n data=8 stop=1 dtr=on rts=on", &dcb)) {   
          // Couldn't build the DCB. Usually a problem
          // with the communications specification string.
          return FALSE;
    }

    // Update DCB rate.
    //dcb.BaudRate =  RTP_TERM_AUX_BAUD_RATE;

    // Set new state.
    if (!SetCommState(hComm, &dcb))
    {
      // Error in SetCommState. Possibly a problem with the communications 
      // port handle or a problem with the DCB structure itself.
    } 

    /* JRT - Get the timeout and set it appropriately */
    rtp_memset(&comm_timeouts, 0x0, sizeof(comm_timeouts));

#define GET_COMM_TIMEOUTS 0
#if GET_COMM_TIMEOUTS
    GetCommTimeouts(hComm, &comm_timeouts);
#endif

    if (!SetCommTimeouts(hComm, &comm_timeouts))
    {
        char err_string[100];
        int error;
        
        error = GetLastError();
        rtp_sprintf(err_string,
                    "rtp_term_aux_open: SetCommTimeouts failed, error = %d\n",
                    error);
        rtp_term_puts(err_string);
        return (-1);
    }

    auxComm = (RTP_HANDLE) hComm;
    
    return (auxComm);
 
}
Esempio n. 17
0
// ---------------------------------------------------- 
// ENTRY POINT
// ---------------------------------------------------- 
int smbservermain(void)
{
    char c;
    int go;
    int  have_printer;
    byte security_mode;
    RTP_THREAD new_thread;
#ifndef RTSMB_RTIP
    int spinState = 0;
    char spinner[4] = {'\\', '-', '/', '|'};
#endif

    // ------------------------------------------------ 
#if (INCLUDE_RTIP)
    rtp_memcpy(my_ip_srv_address, my_ip_address, IP_ALEN);
    rtp_memcpy(ip_srv_mask_address, ip_mask_address, IP_ALEN);
#endif

    // ------------------------------------------------ 
    rtp_printf("\n\nRun Alt Port Numbers(Y/y) or Well-Known(N/n)");
    while (!kbhit ())
    {       
    }
    c = getch ();
    if (c == 'Y' || c == 'y')
    {
        rtsmb_init_port_alt ();
    }
    
    if (c == 'N' || c == 'n')
    {
        rtsmb_init_port_well_know ();
    }

    // ------------------------------------------------ 
    if (!rtp_file_mkdir (SHARE_PATH))
    {
        rtp_printf("WARNING: mkdir of SHARE_PATH failed %s\n", SHARE_PATH, 0);
    }

    rtp_printf("\nsmbservermain - enter\n");
    go = 1;
    /* Start ertfs on windows*/
    //pc_ertfs_init ();

    /* initialize server */
    rtsmb_srv_init (my_ip_srv_address, ip_srv_mask_address, 
                    NETWORK_NAME , NETWORK_GROUP);
    rtp_printf ("Initialized rtsmb\n");

#ifdef USE_CONFIG_FILE
    rtsmb_srv_read_config ("smb_config.txt");
#else

    rtp_printf("Note: The demo does not actually print data, it just captures print data to a temporary file.\n");

    {
    char printerName[32];
    char driverName[32];
    char tempPath[32];
    char prnFile[32];

        rtp_strcpy(printerName, "SmbPrinter");
        rtp_strcpy(driverName, "HP LaserJet 1100");
        rtp_strcpy(tempPath, TEMP_PATH);
        rtp_strcpy(prnFile, "SmbPrintData.prn");

        have_printer = in_printer(printerName,driverName, tempPath, prnFile);
        if (have_printer)
        {
            rtsmb_srv_share_add_printer (printerName, driverName, 1, (PSMBFILEAPI)0, tempPath, 0, (PFCHAR)0, prnFile);
        }
    }
    security_mode = in_loginmode();

    //rtsmb_srv_share_add_tree (SHARE_NAME, DESCRIPTION,  NULL, SHARE_PATH, SHARE_FLAGS_8_3, SECURITY_READWRITE, NULL);
    //rtsmb_srv_share_add_tree (SHARE_NAME, DESCRIPTION, (PSMBFILEAPI)0, SHARE_PATH, SHARE_FLAGS_CREATE, SECURITY_READWRITE, (PFCHAR)0);

    rtsmb_srv_share_add_ipc ((PFCHAR)0);

    rtsmb_srv_set_mode (security_mode);  /* AUTH_USER_MODE or AUTH_SHARE_MODE */

    rtsmb_srv_register_group ("rw_access");
    rtsmb_srv_register_group ("rd_access");

    {
    char shareName[32];
    char sharePath[32];
    char shareDesc[32];
    char sharePass[32];
    char secCode[32];

        rtp_strcpy(shareName, SHARE_NAME);
        rtp_strcpy(shareDesc, "Rtsmbshare");
        rtp_strcpy(sharePath, SHARE_PATH);
        rtp_strcpy(sharePass, "");
        rtp_strcpy(secCode,"2");

        if (in_share(security_mode, shareName, sharePath, shareDesc, sharePass, secCode))
        {
        byte security_mode; /* Defult is 2  SECURITY_READWRITE */
        char *psharePass;
            if (sharePass[0])
                psharePass = &sharePass[0];
            else
                psharePass = 0;
            security_mode = (byte)(secCode[0] -'0');
            rtsmb_srv_share_add_tree (shareName, shareDesc, (PSMBFILEAPI)0, sharePath, SHARE_FLAGS_CREATE, security_mode, (PFCHAR)psharePass);
            rtsmb_srv_set_group_permissions ("rw_access", shareName, SECURITY_READWRITE);
            rtsmb_srv_set_group_permissions ("rd_access", shareName, SECURITY_READ);
        }
    }

    //  rtsmb_srv_set_group_permissions ("rw_access", SHARE_NAME, SECURITY_READWRITE);
    rtsmb_srv_set_group_permissions ("rw_access", "IPC$", SECURITY_READWRITE);
    rtsmb_srv_set_group_permissions ("rd_access", "IPC$", SECURITY_READWRITE);

    //rtsmb_srv_register_group ("ro_access");
    //rtsmb_srv_set_group_permissions ("ro_access", SHARE_NAME, SECURITY_READ);
    //rtsmb_srv_set_group_permissions ("ro_access", "IPC$", SECURITY_READWRITE);

    //rtsmb_srv_register_group ("wo_access");
    //rtsmb_srv_set_group_permissions ("wo_access", SHARE_NAME, SECURITY_WRITE);
    //rtsmb_srv_set_group_permissions ("wo_access", "IPC$", SECURITY_READWRITE);

    /* No access */
    //rtsmb_srv_register_group ("nonebs");
    //rtsmb_srv_set_group_permissions ("nonebs", SHARE_NAME, SECURITY_NONE);
    //rtsmb_srv_set_group_permissions ("nonebs", "IPC$", SECURITY_NONE);

    //rtsmb_srv_register_user (SMB_GUESTNAME, (PFCHAR)0);
    //rtsmb_srv_register_user (SMB_GUESTNAME, "ebs");
    //rtsmb_srv_add_user_to_group (SMB_GUESTNAME, "rw_access");

    if (security_mode == AUTH_USER_MODE)
    {
    char userName[32];
    char userPass[32];
    char userPerm[32];

        if (in_guestaccount())
            rtsmb_srv_register_user (SMB_GUESTNAME, (PFCHAR)0);

        rtp_strcpy(userName, "user");
        rtp_strcpy(userPass, "password");
        rtp_printf("Add users, enter a blank user to stop : ");
        while (in_user(userName, userPass, userPerm))
        {
            rtsmb_srv_register_user (userName, userPass);
            if (rtp_strcmp(userPerm, "rw") == 0)
                    {rtsmb_srv_add_user_to_group (userName, "rw_access");break;}
            else if (rtp_strcmp(userPerm, "r") == 0)
                {rtsmb_srv_add_user_to_group (userName, "rd_access");break;}
        }
    }

#endif //USE_CONFIG_FILE

#if (1)
    if (rtp_thread_spawn (
                &new_thread,
                (RTP_ENTRY_POINT_FN) rtsmb_main,
                (const char *) "RTIP_SMB_SRV",
                STACKSIZE_HUGE_INDEX,
                TASKPRIO_NORMAL_INDEX,
                (void *) 0
            ) < 0)
        {
            rtp_term_puts("spawn of SMB task failed");
            return(-1);
        }
        rtp_term_puts("spawn of SMB task WORKED");

        while (1)
        {
#ifndef RTSMB_RTIP
            spinState += 1;
            spinState = spinState%4;
            rtp_printf("\b%c",spinner[spinState]);

#endif
            rtsmb_srv_cycle (1000);
        }

#else
    //Main Loop
    while(go)
    {
        rtsmb_main ();
        if(rtp_term_kbhit())
        {
//          switch (getch())
            switch (rtp_term_getch())
            {
            case 'q':   go = 0;
                        break;
            default:    break;
            }
        }
    }

    //Shutdown
    rtp_printf("main: shutting down\n");

    rtsmb_srv_shutdown ();
    rtp_net_exit ();
#endif
    return(0);
}//main
Esempio n. 18
0
/*----------------------------------------------------------------------*
                            rtp_term_aux_getch
 *----------------------------------------------------------------------*/
int rtp_term_aux_getch ()
{

    unsigned long dwRead;
    unsigned char buffer;
    unsigned long ret;

    HANDLE hComm;
    OVERLAPPED osReader = {0};
    
    hComm = (HANDLE) auxComm;

    // Create the overlapped event. Must be closed before exiting
    // to avoid a handle leak.
    osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

    if (osReader.hEvent == NULL)
    {
        rtp_term_puts("rtp_term_aux_getch: Error creating overlapped event; abort\n");
        return -1;
    }

    do
    {// Issue read operation.
        if (!ReadFile(hComm, &buffer, 1, &dwRead, &osReader)) 
        {
            if (GetLastError() != ERROR_IO_PENDING)     // read not delayed?
            {
                            rtp_term_puts("rtp_term_aux_getch: Error in communications; report it.\n");
                return (-1);
            }
            else
            {
                /* wait for 1ms */
                do
                {
                    ret = WaitForSingleObject(osReader.hEvent, 0);

                    poll_os_cycle();

                }while (ret == WAIT_TIMEOUT);
    
                switch(ret)
                {
                    // Read completed.
                    case WAIT_OBJECT_0:
                        if (!GetOverlappedResult(hComm, &osReader, &dwRead, FALSE))
                        {
                            // Error in communications; report it.
                            rtp_term_puts("rtp_term_aux_getch: Error in communications; report it.\n");
                        }
                        else
                        {
                            // Read completed successfully.
                            //HandleASuccessfulRead(buffer, dwRead);
                        }
                        break;
    
                    case WAIT_TIMEOUT:
                        break;                       
    
                    default:
                        // Error in the WaitForSingleObject; abort.
                        // This indicates a problem with the OVERLAPPED structure's
                        // event handle.
                        break;
                }
            }
        }
        else
        {
        // read completed immediately
        //HandleASuccessfulRead(buffer, dwRead);
        }
        poll_os_cycle();
//tvotvo        TERMINAL_AUX_THREAD_SLEEP(100);
    }while (dwRead == 0);
    
    CloseHandle(osReader.hEvent);
    
    return (int) buffer;
    
}