int copy_stream(int fd,int f) { int nread,nwrite; char buffer[8192]; int timeout=20,wait; PRINT("copy_stream\n"); while ((nread = read(fd, buffer, sizeof(buffer))) > 0) { int index=0,countread; // nwrite=fwrite(buffer, sizeof(char), nread, f); /* Lisa:fwrite => write */ while (index < nread ) { countread=nread-index; nwrite=write(f,&buffer[index],countread); index += nwrite; if ((wait=waitsock(f,timeout,0))==0) check_prn_status("Busy or Error",clientaddr); } check_prn_status("Printing",clientaddr); //Add by Lisa } (void)fflush(f); // (STS) { // (STS) wait 30 seconds for completion fd_set rfds; struct timeval tv; FD_ZERO(&rfds); FD_SET(f, &rfds); tv.tv_sec = 30; tv.tv_usec = 0; select(1, NULL, &rfds, NULL, &tv); } check_prn_status("ONLINE",""); //Add by Lisa return (nread); }
DWORD RECV(int sockfd , PBYTE pRcvbuf , DWORD dwlen , struct sockaddr *from, int *fromlen , DWORD timeout) { if ( waitsock(sockfd , timeout , 0) == 0) { //timeout PRINT("RECV timeout %d\n",timeout); return -1; } return recvfrom(sockfd, pRcvbuf , dwlen , 0 , from , fromlen ); }
int closesocket(int sockfd) { /* Clear the UDP socket */ char dummy[1024]; int iLen , res; //PRINT("closesocket ... \n"); res = waitsock(sockfd , 1 , 0); //PRINT("waitsock res %d\n",res); if (res == 1) { iLen = recvfrom(sockfd, dummy , sizeof(dummy) , 0,NULL,0 ); } else { iLen = 0; } //PRINT("iLen %d\n",iLen); if (iLen == sizeof(dummy)) { res = waitsock(sockfd , 1 , 0); } else { return 0; } while (res == 1) { iLen = recvfrom(sockfd, dummy , sizeof(dummy) , 0,NULL,0 ); //PRINT("iLen = %d\n",res); res = waitsock(sockfd , 0 , 100); } return 0; }
DWORD RECV(int sockfd , PBYTE pRcvbuf , DWORD dwlen , DWORD timeout) { if( waitsock(sockfd , timeout , 0) == 0) { //timeout PRINT("RECV timeout %d\n",timeout); return -1; } return recv(sockfd , pRcvbuf , dwlen , 0 ); }
int processReq(int sockfd) { // IBOX_COMM_PKT_HDR* phdr; int /*iLen , iRes , iCount , */iRcv; int fromlen; char *hdr; char pdubuf[INFO_PDU_LENGTH]; struct sockaddr_in from_addr; unsigned short cli_port; memset(pdubuf,0,sizeof(pdubuf)); //PRINT("Enter processReq\n"); if ( waitsock(sockfd , 1 , 0) == 0) { return -1; } fromlen = sizeof(from_addr); //Receive the complete PDU iRcv = RECV(sockfd , pdubuf , INFO_PDU_LENGTH , (struct sockaddr *)&from_addr , &fromlen , 1); if (iRcv != INFO_PDU_LENGTH) { closesocket(sockfd); return (-1); } hdr = pdubuf; cli_port = ntohs(from_addr.sin_port); //_dprintf("[InfoSvr] Client Port: %d\n", cli_port); processPacket(sockfd, hdr, cli_port); /* J++ closesocket(sockfd); */ }
int copy_stream(int fd,int f) { int nread,nwrite; char buffer[8192]; int timeout=20, wait; int busyflag=0; //PRINT("copy_stream\n"); while ((nread = read(fd, buffer, sizeof(buffer))) > 0) { int index=0,countread; // nwrite=fwrite(buffer, sizeof(char), nread, f); /* Lisa:fwrite => write */ check_prn_status("Printing", clientaddr); //Add by Lisa while (index < nread ) { countread=nread-index; nwrite=write(f, &buffer[index],countread); if (nwrite<0) { logmessage("lpd", "write error : %d\n", errno); check_prn_status("Busy or Error", clientaddr); return(nread); } #ifdef REMOVE else if (nwrite==0) { syslog(LOG_NOTICE, "write error 4: %d\n", nwrite); check_prn_status("Busy or Error",clientaddr); busyflag=1; } #endif else if ((wait=waitsock(f,timeout,0))==0) { //logmessage("lpd", "write error %d\n", errno); check_prn_status("Busy or Error",clientaddr); busyflag=1; } else if(wait<0) { logmessage("lpd", "can not write : %d\n", errno); check_prn_status("Busy or Error",clientaddr); return(nread); } else { index+=nwrite; if (busyflag==1) { busyflag = 0; check_prn_status("Printing",clientaddr); } } } } //(void)fflush(f); check_prn_status(ONLINE,""); //Add by Lisa return (nread); }
int copy_stream(int fd,int f) { int nread,nwrite; char buffer[8192]; int timeout=20, wait; int busyflag=0; //PRINT("copy_stream\n"); while ((nread = read(fd, buffer, sizeof(buffer))) > 0) { int index=0,countread; // nwrite=fwrite(buffer, sizeof(char), nread, f); /* Lisa:fwrite => write */ check_prn_status("Printing", clientaddr); //Add by Lisa while (index < nread ) { countread=nread-index; nwrite=write(f, &buffer[index],countread); if (nwrite<0) { logmessage("lpd", "write error : %d\n", errno); check_prn_status("Busy or Error", clientaddr); return(nread); } #ifdef REMOVE else if (nwrite==0) { syslog(LOG_NOTICE, "write error 4: %d\n", nwrite); check_prn_status("Busy or Error",clientaddr); busyflag=1; } #endif else if ((wait=waitsock(f,timeout,0))==0) { //logmessage("lpd", "write error %d\n", errno); check_prn_status("Busy or Error",clientaddr); busyflag=1; } else if(wait<0) { logmessage("lpd", "can not write : %d\n", errno); check_prn_status("Busy or Error",clientaddr); return(nread); } else { index+=nwrite; if (busyflag==1) { busyflag = 0; check_prn_status("Printing",clientaddr); } } } } (void)fflush(f);// (STS) { // (STS) wait 30 seconds for completion fd_set rfds; struct timeval tv; FD_ZERO(&rfds); FD_SET(f, &rfds); tv.tv_sec = 30; tv.tv_usec = 0; select(1, NULL, &rfds, NULL, &tv); } check_prn_status(ONLINE,""); //Add by Lisa return (nread); }