Error Bad File Descriptor C
Contents |
here for a quick overview of the site Help bad file descriptor c socket Center Detailed answers to any questions you might have
What Is Bad File Descriptor
Meta Discuss the workings and policies of this site About Us Learn more about bad file descriptor error in linux Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges what does bad file descriptor mean Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Bad File Descriptor with Linux Socket write() Bad File Descriptor C up vote -1
Bad File Descriptor Vlc
down vote favorite I have an interesting problem with write(2) function. PrepareResponseForSetCoordinates function causes bad file descriptor error on write. Here is the line of error: perror("ERROR writing to socket"); total output: ERROR writing to socket: Bad file descriptor I am sure that I have established the connection because PrepareResponseForConnectionTest works like a charm. Can you have any idea about the reason of the error? When I use gcc as compiler there was no problem. After that because of using multiple new cpp sources I am using g++ as compiler and I have this error. Regards Here below my code: #define MAX_PMS_MESSAGE_LEN (4096) unsigned char baCommBuffer[MAX_PMS_MESSAGE_LEN]; unsigned char PrepareResponseForSetCoordinates(void) { unsigned char baTempBuff[255]={0}; unsigned short bCnt=0,i=0,bCsum=0,bCnt2=0; time_t lEpochTime; time_t lSessionTime; memset(baTempBuff,0,sizeof(baTempBuff)); memset(baCommBuffer,0,sizeof(baCommBuffer)); bzero(baCommBuffer,MAX_PMS_MESSAGE_LEN); bzero(baTempBuff,sizeof(baTempBuff)); lEpochTime = time(NULL); baCommBuffer[bCnt++] = START_CHAR; baCommBuffer[bCnt++] = START_CHAR; baCommBuffer[bCnt++] = PACKET_SEPERATOR; sprintf((char*)baTempBuff,"%ld",(unsigned long)lEpochTime); memcpy(baCommBuffer+bCnt,b
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings bad file descriptor pipe and policies of this site About Us Learn more about Stack Overflow bad file descriptor shell script the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
Bad File Descriptor Windows
Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it http://stackoverflow.com/questions/11258781/bad-file-descriptor-with-linux-socket-write-bad-file-descriptor-c only takes a minute: Sign up What is bad file descriptor in c? up vote 1 down vote favorite This is my code of function that wants to read file: int sendByByte(int filed,int sockfd,int filesize) { int i=0; int sent=0; char buf[BUFSIZE]; while(i
for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Ask a Question Ask for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Expand https://www.experts-exchange.com/questions/23957725/Getting-error-bad-file-descriptor-in-very-simple-open-and-flock-statements.html Search Submit Close Search Login Join Today Products BackProducts Gigs Live Careers Vendor Services https://ftp.gnu.org/old-gnu/Manuals/glibc-2.2.3/html_node/libc_17.html Groups Website Testing Store Headlines Experts Exchange > Questions > Getting error "bad file descriptor" in very simple open() and flock() statements Want to Advertise Here? Solved Getting error "bad file descriptor" in very simple open() and flock() statements Posted on 2008-12-04 Linux Distributions C Linux 1 Verified Solution 5 Comments 4,591 Views Last Modified: 2013-12-06 Alright, I bad file agree I'm dumb :( I wrote these 4 very simple lines in a C Program, (in Red Hat Enterprise Linux 4) and ran it to get "Bad File Descriptor" error int fd = open("something.txt",O_CREAT| O_APPEND, (mode_t)777); if(fd<0) perror("Can't open file"); if(write(fd, "Test String", 100)==-1) perror("Can't write to file"); After hours of playing with these flags etc., I could not make it run. Of course, the value of bad file descriptor fd is not -1, so it seems it is opening the file properly(?) but not writing in it. I also tried opening a file with proper permissions and still the same error. (Please don't bother suggesting reducing that '100' to reasonable value, because that doesn't matter. ) But my problem is not this. Strangely, the write() method worked without errors when I replaced open with fopen, FILE *fp = fopen("something.txt", "w+"); and then using int fd = fileno(fp); to get the file descriptor (I NEED TO USE file descriptor) But again, when I lock the file with flock(fd, LOCK_EX | LOCK_NB); It returns -1 and gives the same error : Bad File Descriptor.. What is all this happening? How to correct this? Thanks a lot !! (B/w, I just realized, experts-exchange's code pasting is not that good. I can only paste one code snippet it seems and cannot if I want to write some comments of my own after each code snippet). 0 Question by:piyush_soni Facebook Twitter LinkedIn Google LVL 53 Best Solution byInfinity08 >> int fd = open("something.txt",O_CREAT| O_APPEND, (mode_t)777); Make that : int fd = open("something.txt", O_WRONLY | O_CREAT | O_APPEND, (mode_t) 0777); So, add the O_WRONLY flag, Go to Solution 5 Comments LVL 53 Overall: Level 53 C 35 Linux 6 Linux Distributions
GNU system, but they can occur using the GNU library on other systems. Macro: int EPERM Operation not permitted; only the owner of the file (or other resource) or processes with special privileges can perform the operation. Macro: int ENOENT No such file or directory. This is a "file doesn't exist" error for ordinary files that are referenced in contexts where they are expected to already exist. Macro: int ESRCH No process matches the specified process ID. Macro: int EINTR Interrupted function call; an asynchronous signal occurred and prevented completion of the call. When this happens, you should try the call again.
You can choose to have functions resume after a signal that is handled, rather than failing with EINTR; see section Primitives Interrupted by Signals. Macro: int EIO Input/output error; usually used for physical read or write errors. Macro: int ENXIO No such device or address. The system tried to use the device represented by a file you specified, and it couldn't find the device. This can mean that the device file was installed incorrectly, or that the physical device is missing or not correctly attached to the computer. Macro: int E2BIG Argument list too long; used when the arguments passed to a new program being executed with one of the exec functions (see section Executing a File) occupy too much memory space. This condition never arises in the GNU system. Macro: int ENOEXEC Invalid executable file format. This condition is detected by the exec functions; see section Executing a File. Macro: int EBADF Bad file descriptor; for example, I/O on a descriptor that has been closed or reading from a descriptor open only for writing (or vice versa). Macro: int ECHILD There are no child processes. This error happens on operations that are supposed to manipulate child processes, when there aren't any