hello, sorry for all the posts on this topic. I finally got tweaking on the code some more and fixed the problem. everything is working great. Thanks chris, and to the other poster who answered back.
----- Original Message ----- From: Tyler Littlefield To: [email protected] Sent: Thursday, January 01, 2009 3:25 PM Subject: Re: [c-prog] file getting set to 0 length? p.s. A friend pointed out the problem with me creating the string and then reassigning to the pointer... I'm to used to c#, wasn't thinking. I fixed it, and it shows connection info, but the file still gets zeroed out with the pole function. ----- Original Message ----- From: Tyler Littlefield To: [email protected] Sent: Thursday, January 01, 2009 1:50 PM Subject: Re: [c-prog] file getting set to 0 length? P.S. I've ran gdb on this and traced it through about 30 loops. I watched the while loop for a bit, then dropped down in to the pole function and watched that loop. doesn't seem to be a prob with execution. ----- Original Message ----- From: Tyler Littlefield To: [email protected] Sent: Thursday, January 01, 2009 1:43 PM Subject: [c-prog] file getting set to 0 length? Hello list, I've got a quick question. I have a function that is being called numerous times in a loop. Before this function is called, things seem to work great. Now when I call this function, my log, or the length of the log anyway is set to 0. Any ideas why this might be? here's the function. POLE_ERR Server::Pole() { fd_set read; int incoming=0; sockaddr_in addr; memset(&addr,0,sizeof(addr)); if ((select((this->maxfd+1),&read,NULL,NULL,NULL)==-1)) { return E_SELECT; } for (int i=0;i<=this->maxfd;i++) { //see if the fd is in the list of active connections. if ((FD_ISSET(i,&read))) { //see if a connection came in on the listening socket. if (this->listener==i) { //accept the connection socklen_t len=sizeof(addr); if ((incoming=accept(this->listener,(sockaddr*)&addr,&len)==-1)) { return E_ACCEPT; } User *usr=new User(incoming,addr); FD_SET(incoming,&this->master); //update the max file descriptor if (incoming<this->maxfd) { this->maxfd=incoming; } this->connections.push_back(usr); char* msg=new char[128]; msg=(char*)"New connection from: "; strcat(msg,inet_ntoa(addr.sin_addr)); string message=msg; cout << message << endl; cout << "Wrote message" << endl; delete []msg; Log::WriteLog(message); } } } return E_SUCCESS; } Before I had this function returning an error enum, it would just return true or false, and the log would be written with the error. Now it returns an error, but the log still gets erased. here's my write function also, if it helps. Well, I'll provide the whole log setup. #include "log.h" //we define our namespace so that we won't have conflicting functions: namespace Log { static ofstream LogOut; static BOOL LoggerInitialized=false; BOOL InitializeLogger() { #ifdef WRITE_SYSLOG openlog(MUD_NAME.c_str(),LOG_PID,0); #endif LogOut.open("log.log"); LoggerInitialized=true; return true; } BOOL WriteLog(string message) { if (!LoggerInitialized) { return false; } cout << message << endl; #ifdef WRITE_SYSLOG syslog(LOG_MAKEPRI(LOG_DAEMON,LOG_INFO),message.c_str()); #endif int i=message.length(); if (message[i]!='\n') { message+="\n"; } int pid=getpid(); string output; stringstream conv; conv << pid; output=conv.str(); output+=":"+message; LogOut << output; cout << output; return true; } BOOL CloseLog() { if (!LoggerInitialized) { return false; } #ifdef WRITE_SYSLOG closelog(); #endif LogOut.close(); LoggerInitialized=false; return true; } } Your help on this would be great. TIA, [Non-text portions of this message have been removed] [Non-text portions of this message have been removed] [Non-text portions of this message have been removed] [Non-text portions of this message have been removed]
