Thread: problem with creating a thread

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    problem with creating a thread

    Hii all..

    I am harika.. i have to develop a web server.. so, in that process.. i have a problem with the concept of using multiple threads.. actually, i have to excute GET cmd.. i am getting a problem in the 42nd line of my code.. i have highlighted it with bold and underline.. can any one help me out with this code??

    Code:
    #include<stdio.h>
    #include<sys/socket.h>
    #include<netinet/in.h>
    #include<sys/types.h>
    #include<pthread.h>
    #include<stdlib.h>
    void do_404(char *item, FILE *fp);
    void process( char *rq, FILE *fp);
    int main(int ac, char *av[])
    {
    char *buf;
    int counter=0;
    FILE *fp, *fpin, *fpout;
    struct sockaddr_in addr;
    addr.sin_family= AF_INET;
    addr.sin_port=htons(7000);
    char *request;
    char hostname[256];
    int adlen,fd,bd,new,ln;
    pthread_t thread1, thread2;
    fd=socket(AF_INET, SOCK_STREAM, 0);
    bd=bind(fd, (struct sockaddr *)&addr, sizeof(addr));
    //if(fd== -1)
    //perror("Creation error");
    //if(bd== -1)
    //perror("socket binding failed");
    sleep(4);
    ln=listen(fd, 1);
    adlen=sizeof(struct sockaddr_in);
    while(1)
    {
    new=accept(fd, (struct sockaddr *)&addr, &adlen);
    if(new<0)
    perror("accepting error");
    //else
    //printf("Received ne client on socket=%d\n", new);
    fpin=fdopen(fd, "r");
    fpout=fdopen(fd, "w");
    fgets(request, BUFSIZ, fpin);
    while(fgets(buf, BUFSIZ, fp)!=NULL && strcmp(buf, "\r\n")!=0);
    
    [tag]pthread_create(&thread1, NULL, &process(request, fpout), NULL);[/tag]
    
    pthread_join(thread1, NULL);
    printf("\n");
    exit(0);
    fclose(fpin);
    fclose(fpout);
    }
    return 0;
    }
    
    void process(char *rq, FILE *fp)
    {
    char *item, *cmd, *arg;
    if (scanf(rq, "%s%s", cmd, arg)!=2)
    return;
    if (strcmp(cmd, "GET")==0)
    {
    if( not_exist(item))
    do_404(item, fp);
    }
    exit(0);
    }
    
    void do_404(char *item, FILE *fp)
    {
    fprintf(fp,"\r\n");
    fflush(fp);
    }
    Last edited by neeharikach; 11-28-2010 at 03:52 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    While you're waiting, read this -> << !! Posting Code? Read this First !! >>
    Then edit your post for readability.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling GNU MP
    By mattnp12 in forum C Programming
    Replies: 3
    Last Post: 06-23-2011, 03:58 PM
  2. Replies: 1
    Last Post: 06-25-2010, 07:14 AM
  3. Listening socket and thread problem
    By esaptonor in forum Windows Programming
    Replies: 6
    Last Post: 06-19-2010, 03:04 AM
  4. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  5. Simple thread object model (my first post)
    By Codeplug in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2004, 11:34 PM