Click here to Skip to main content
15,921,989 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionsyntax error '<' Pin
gr8coaster32929-Oct-05 19:39
gr8coaster32929-Oct-05 19:39 
AnswerRe: syntax error '<' Pin
Ghasrfakhri29-Oct-05 19:22
Ghasrfakhri29-Oct-05 19:22 
QuestionRe: syntax error '<' Pin
gr8coaster32930-Oct-05 4:49
gr8coaster32930-Oct-05 4:49 
QuestionRe: syntax error '<' Pin
David Crow31-Oct-05 3:37
David Crow31-Oct-05 3:37 
QuestionRe: syntax error '<' Pin
gr8coaster32931-Oct-05 9:26
gr8coaster32931-Oct-05 9:26 
AnswerRe: syntax error '<' Pin
David Crow31-Oct-05 9:49
David Crow31-Oct-05 9:49 
QuestionPrinting an image Pin
DanYELL29-Oct-05 17:07
DanYELL29-Oct-05 17:07 
AnswerRe: Printing an image Pin
Christian Graus30-Oct-05 11:41
protectorChristian Graus30-Oct-05 11:41 
GeneralRe: Printing an image Pin
DanYELL30-Oct-05 16:50
DanYELL30-Oct-05 16:50 
GeneralRe: Printing an image Pin
Christian Graus30-Oct-05 16:53
protectorChristian Graus30-Oct-05 16:53 
QuestionSPDRP_FRIENDLYNAME Pin
LiYS29-Oct-05 16:41
LiYS29-Oct-05 16:41 
QuestionCListCtrl Error Pin
Allad29-Oct-05 15:05
Allad29-Oct-05 15:05 
Questionnumber picker thingie Pin
alex@zoosmart.us29-Oct-05 12:11
alex@zoosmart.us29-Oct-05 12:11 
AnswerRe: number picker thingie Pin
Joe Woodbury29-Oct-05 13:06
professionalJoe Woodbury29-Oct-05 13:06 
GeneralRe: number picker thingie Pin
alex@zoosmart.us30-Oct-05 12:05
alex@zoosmart.us30-Oct-05 12:05 
GeneralRe: number picker thingie Pin
Joe Woodbury30-Oct-05 17:19
professionalJoe Woodbury30-Oct-05 17:19 
Questionsort structures Pin
kerrywes29-Oct-05 9:57
kerrywes29-Oct-05 9:57 
AnswerRe: sort structures Pin
Chris Losinger29-Oct-05 12:03
professionalChris Losinger29-Oct-05 12:03 
AnswerRe: sort structures Pin
Joe Woodbury29-Oct-05 13:11
professionalJoe Woodbury29-Oct-05 13:11 
AnswerRe: sort structures Pin
Ghasrfakhri29-Oct-05 19:21
Ghasrfakhri29-Oct-05 19:21 
Questioncant signin to homtmail using Pin
whatever8929-Oct-05 9:29
whatever8929-Oct-05 9:29 
Questionfile system type Pin
Chintoo72329-Oct-05 7:26
Chintoo72329-Oct-05 7:26 
AnswerRe: file system type Pin
Mircea Puiu29-Oct-05 7:45
Mircea Puiu29-Oct-05 7:45 
Questiontooltip for CDC drawing areas ?? Pin
tbrake29-Oct-05 6:15
tbrake29-Oct-05 6:15 
Questionmulti thread sinz Pin
jojojojoj29-Oct-05 3:51
jojojojoj29-Oct-05 3:51 
hello list, i am having some trouble with thread sinc in a multithread program i am developing.

the problems is i dont know how many threads i will have in my program, here is some code:

void CAsyncClientDlg::CleanupThread()
{
CString n;
GetDlgItemText(IDC_SIMULTANEOS, n);
int a = _ttoi(n.GetBuffer(n.GetLength()));


for(LONG i=0; i<a; i++)="" {


="" if="" (m_pclientthread[i])
="" {=""
="" (::postthreadmessage(m_pclientthread[i]-="">m_nThreadID, WM_TERM_THREAD, 0, 0) == 0)
TRACE(_TEXT("Thread 0x%02x possibly already terminated\n"), m_pClientThread[i]->m_nThreadID);

// wait up to 1s for secondary threads to terminate
// termEvent will be signaled when thread count reaches 0
if (termEvent.Lock(1000))
TRACE(_TEXT("Threads terminated gracefully\n"));
else
TRACE(_TEXT("WARNING: All secondary thread(s) not gracefully terminated.\n"));
}


}
}

void CAsyncClientDlg::OnConnect()
{
CString str;
GetDlgItemText(IDC_SERVERNAME, str);
CString n;
GetDlgItemText(IDC_SIMULTANEOS, n);
int a = _ttoi(n.GetBuffer(n.GetLength()));
// validate that the number is <= MAX_NUMBER_OF_THREADS
for(LONG variable=0; variable<a; variable++)="" {
=""

="" create="" a="" thread="" to="" handle="" the="" connection.="" is="" created="" suspended="" so="" that="" we="" can
="" set="" variables="" in="" cclientthread="" before="" it="" starts="" executing.
="" cclientthread*="" pthread="(CClientThread*)AfxBeginThread(RUNTIME_CLASS(CClientThread)," thread_priority_normal,="" 0,="" create_suspended);
="" if="" (!pthread)
="" setdlgitemtext(idc_connectionstatus,="" cstring("could="" not="" connected="" ")="" +="" str);
="" trace(_text("could="" thread\n"));
="" return;
="" }
="" trace(_text("casyncclientdlg::onconnect()\n"));
="" getdlgitem(idc_connect)-="">EnableWindow(FALSE);


m_strServerName = str;
pThread->m_strServerName = str; // server machine name
pThread->m_socket.m_pThread = pThread; // the thread that m_socket lives
m_pClientThread[variable] = pThread; // keep a pointer to the connect socket thread

pThread->m_socket.CreateConnector(m_pContext);


// Now start the thread.
pThread->ResumeThread();
}
}

void CAsyncClientDlg::OnDisconnect()
{

CString n;
GetDlgItemText(IDC_SIMULTANEOS, n);
int a = _ttoi(n.GetBuffer(n.GetLength()));

for(LONG i=0; i<a; i++)="" {
="" if="" (m_pclientthread[i])
="" (::postthreadmessage(m_pclientthread[i]-="">m_nThreadID, WM_TERM_THREAD, 0, 0) == 0)
TRACE(_TEXT("Thread 0x%02x possibly already terminated\n"), m_pClientThread[i]->m_nThreadID);
}
}
}


LRESULT CAsyncClientDlg::OnConnectionClose(WPARAM, LPARAM)
{

CString n;
GetDlgItemText(IDC_SIMULTANEOS, n);
int a = _ttoi(n.GetBuffer(n.GetLength()));

for(LONG i=0; i<a; i++)="" {
="" m_pclientthread[i]="NULL;
" }
}

lresult="" casyncclientdlg::onnewmessage(wparam="" wparam,="" lparam)
{
="" cstring="" strrecv="CString((TCHAR" *)wparam);
="" m_received="m_received" +="" strrecv;
="" updatedata(false);
=""
="" return="" 0l;
}

void="" casyncclientdlg::onmail()=""
{
="" n;
="" getdlgitemtext(idc_simultaneos,="" n);
="" int="" a="_ttoi(n.GetBuffer(n.GetLength()));
" for(long="" variable="0;" variable<a;="" variable++)="" if="" (m_pclientthread[variable]="" &&="" (m_pclientthread[variable]-="">m_socket).m_fConnected)
{
CString str, desde, hasta, subject, mensaje, cdesde, cresponder;
GetDlgItemText(IDC_EDESDE, desde);
GetDlgItemText(IDC_ESUBJECT, subject);
GetDlgItemText(IDC_EMENSAJE, mensaje);
GetDlgItemText(IDC_CABDESDE, cdesde);
GetDlgItemText(IDC_CABRESPONDER, cresponder);

str = "ehlo hola\r\n";
(m_pClientThread[variable]->m_socket).Write(str);
str = "auth plain password\r\n";
(m_pClientThread[variable]->m_socket).Write(str);

str = "mail from: <" + desde + ">\r\n"; // nrcpt to: <" + hasta + ">\r\n\r\data\r\nSubject: " + subject + "\r\n\r\n" + mensaje + "\r\n.\r\n";
(m_pClientThread[variable]->m_socket).Write(str);

int numero = m_hasta.GetCount();
for(int k=0; k<numero; k++)="" {

="" m_hasta.gettext(k,="" hasta);

="" str="rcpt to: <" +="" hasta="" "="">\r\n";
(m_pClientThread[variable]->m_socket).Write(str);
MessageBox(hasta);
}


str = "data\r\n";
(m_pClientThread[variable]->m_socket).WriteWebRequest(str);
str = "Subject: " + subject + "\r\n";
(m_pClientThread[variable]->m_socket).Write(str);
str = "From: " + cdesde + "<" + desde + ">\r\n";
(m_pClientThread[variable]->m_socket).Write(str);
str = "In-Reply-To: " + cresponder + "\r\n";
(m_pClientThread[variable]->m_socket).Write(str);
str = "\r\n" + mensaje + "\r\n";
(m_pClientThread[variable]->m_socket).Write(str);
str = "\r\n.\r\n";
(m_pClientThread[variable]->m_socket).Write(str);
str = "quit\r\n";
(m_pClientThread[variable]->m_socket).Write(str);

}
else
{

}
SetDlgItemText(IDC_CONNECTIONSTATUS, "No Connectado");

}

}

The problem is sometimes all the strings on "OnMail" functions goes to the server and i can see the answers on my received windows.
For example when IDC_SIMULTANEOS = 1(1 thread) its works fine.
When threads are bigger than 1 the results on my received window are disordered, here is an example of 2 simultaneous threads sending 3 mails each.


220 mx.gmail.com ESMTP h39sm756279wxd
250-mx.gmail.com at your service
250-SIZE 20971520
250-8BITMIME
250-AUTH LOGIN PLAIN
250 ENHANCEDSTATUSCODES
235 2.7.0 Accepted
250 2.1.0 OK
250 2.1.5 OK
250 2.1.5 OK
250 2.1.5 OK
354 Go ahead
220 mx.gmail.com ESMTP h14sm686078wxd
250-mx.gmail.com at your service
250-SIZE 20971520
250-8BITMIME
250-AUTH LOGIN PLAIN
250 ENHANCEDSTATUSCODES
235 2.7.0 Accepted
250 2.1.0 OK
250 2.0.0 OK 1130593300 h39sm756279wxd
250 2.1.5 OK
250 2.1.5 OK
250 2.1.5 OK
354 Go ahead
250 2.0.0 OK 1130593300 h14sm686078wxd

Thats fine to me, all the commands get executed on the server but sometimes:(same example 2 simultaneous threads sending 3 mails each):

220 mx.gmail.com ESMTP i38sm758995wxd
502 5.5.1 Unrecognized command i38sm758995wxd
250-mx.gmail.com at your service
250-SIZE 20971520
250-8BITMIME
250-AUTH LOGIN PLAIN
250 ENHANCEDSTATUSCODES
235 2.7.0 Accepted
250 2.1.0 OK
250 2.1.5 OK
250 2.1.5 OK
250 2.1.5 OK
354 Go ahead
250 2.0.0 OK 1130593502 i38sm758995wxd
220 mx.gmail.com ESMTP h9sm717398wxd
502 5.5.1 Unrecognized command h9sm717398wxd
250-mx.gmail.com at your service
250-SIZE 20971520
250-8BITMIME
250-AUTH LOGIN PLAIN
250 ENHANCEDSTATUSCODES

The flow was stopped and only 3 mails were send.

My question is why this works well sometimes and sometimes dont if i am inserting the sames values?
I think i can solve it with an event but i dont know where to set and unset.
I search documentation but i never see how to works with threads created like this.

Thanx in advance.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.