multithread in libwww

hello

can anyone help me about following problem?

my OS is SunOS 5.6. I want to make a function(named FuncA) by which I can
send request to a web site and get response from that site.
If the time speicified by main program(as a parameter of FuncA) is over, the
function should return a overtime  error.

it looked like following

main program -> FuncA -> web site -> FuncA -> main program

I use libwww to do that job in FuncA,it did work in non-multithread
environment,but if the main program is one thread of a process , the FuncA
failed.

I checked the libwww document, but found no answer.

follwing is my test program , in which the postSDBService function is what I
called FuncA before.


#include "postSDBService.h"
#include <pthread.h>

PRIVATE void* test(void* arg)
{
  int nRet;
  char *szBuf = NULL;
  unsigned int nBufSize = 0;
  char szErrorMessage[SDB_MSGSIZE+1];

  HTAssocList* paramList = getParamsList();
  printf("!!!!!!!!!!!!!!!!!!!");
  memset((char*)szErrorMessage, 0, sizeof(szErrorMessage));

  setInParam(paramList, "MEBR_NO", "zhxj100000");
  setInParam(paramList, "LOG_OUTPUT_PARAM", "0");

  nRet = postSDBService(  "192.168.3.61",
       8089,
       "KissService_10",
       "ComRefAMCMember",
       "KISS",
       "3",
       "XML",
       "MngCustomer_ComRefAMCMember",
       paramList,
       4000,
       &szBuf,
       &nBufSize,
       (char*)&szErrorMessage);

  if (nRet == 0){
    printf("Success:\n%d\n%s\n", nBufSize, szBuf);
  }else{
    printf("[%d]Failure:\n%s\n", nRet, szErrorMessage);
  }

  deleteParamsList(paramList);
  free(szBuf);

  return;
}

PRIVATE void* test1(void* arg)
{
  int nRet;
  char *szBuf = NULL;
  unsigned int nBufSize = 0;
  char szErrorMessage[SDB_MSGSIZE+1];

  HTAssocList* paramList = getParamsList();
  printf("!!!!!!!!!!!!!!!!!!!");

  memset((char*)szErrorMessage, 0, sizeof(szErrorMessage));

  setInParam(paramList, "MEBR_NO", "1234567890");
  setInParam(paramList, "LOG_OUTPUT_PARAM", "0");

  nRet = postSDBService(    "192.168.3.61",
                            8089,
                            "KissService_5",
                            "MypRefAddress",
                            "MyPage",
                            "3",
                            "XML",
                            "RefMember_MypRefAddress",
                            paramList,
                            20000,
                            &szBuf,
                            &nBufSize,
                            (char*)&szErrorMessage);

  if (nRet == 0){
    printf("Success:\n%d\n%s\n", nBufSize, szBuf);
  }else{
    printf("[%d]Failure:\n%s\n", nRet, szErrorMessage);
  }

  deleteParamsList(paramList);
  free(szBuf);

  return;
}



PRIVATE void* test2(void* arg)
{
 printf("test test test \n");
}

int main(int argc, char* argv[])
{
    pthread_t tid[20];
 pthread_attr_t attr[20];
    int i;
 void * arg;
 void ** status;


 for (i = 0; i < 3; i++) {
  pthread_attr_init(&attr[i]);
  pthread_attr_setstacksize(&attr[i], 2097152);
  pthread_create(&tid[i], &attr[i], test, arg);
  printf("thread  %d\n", tid[i]);
 }

 for (i= 3; i < 6; i++) {
  pthread_attr_init(&attr[i]);
  pthread_attr_setstacksize(&attr[i], 2097152);
  pthread_create(&tid[i], &attr[i], test1, arg);
  printf("thread  %d\n", tid[i]);
 }

 for (i = 0; i < 6; i++) {
  pthread_join(tid[i], status);
 }

 return 0;
}

Received on Friday, 4 October 2002 02:15:43 UTC