I'm trying to reference a function to pthread_create, and i am using the exact same syntax as elsewhere, but it doesn't work. Whats the problem?
Errors:
Code:
g++ -pthread -c parser.cpp
parser.cpp: In method `void ircParser::init (char *, ircserver,
commander)':
parser.cpp:34: no matches converting function `runThread' to type `void
*(*) (void *)'
parser.h:34: candidates are: void *ircParser::runThread (void *)
make: *** [parser.o] Error 1
Here is the code:
Code:
// parser.cpp
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
// #include <regex.h> // Regular Expression (POSIX) Matching
#include <fnmatch.h> // Shell-like Regular Expressions
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <iostream>
#include <fstream> // For cout redirecting
#include <string>
#include <fcntl.h>
#include <sys/ioctl.h> // ioctl
#include <getopt.h>
#include "ircserver.h"
//#include "sockfunc.h"
//#include "ircfunc.h"
#include "nemoirc.h"
#include "logger.h"
#include "parser.h"
// Externs
extern logger logfile;
void ircParser::init(char *iB, ircserver iIS, commander iC) {
serv = iIS;
buf = iB;
cmd = iC;
pthread_t p;
int data = 123,
rc;
init(buf, serv, cmd);
rc = pthread_create( &p, NULL, run, &data );
if( rc != 0 ) {
fprintf( stderr, "pthread_create: %s\n", strerror( rc ) );
} else {
logfile << logfile.stamp() << "** ERROR STARTING PARSE **" << logfile.endl;
}
}
void *ircParser::run(void *arg) {
rawMsg message;
char *type;
if (message.msgParser(buf, serv) != 0) return (void *)NULL;
if (strcmp("PRIVMSG", message.getCommand()) == 0)
logfile << logfile.stamp() << "<" << message.getNick() << "> " << message.getMessage() << logfile.endl;
if (strcmp("NOTICE", message.getCommand()) == 0)
logfile << logfile.stamp() << "-" << message.getNick() << "- " << message.getMessage() << logfile.endl;
cmd.setMessage(message.getSender(), message.getRecipient(), message.getMessage(), message.getCommand(), serv);
cmd.parsePrivmsg();
cmd.parseNotice();
cmd.parseSpecial();
return (void *)NULL;
}
Code:
// parser.h
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
// #include <regex.h> // Regular Expression (POSIX) Matching
#include <fnmatch.h> // Shell-like Regular Expressions
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <iostream>
#include <fstream> // For cout redirecting
#include <string>
#include <fcntl.h>
#include <sys/ioctl.h> // ioctl
#include <getopt.h>
#include "ircserver.h"
//#include "sockfunc.h"
//#include "ircfunc.h"
#include "nemoirc.h"
#include "logger.h"
// External declarations
//extern logger logfile;
//parsedArgs opts;
class ircParser {
private:
//logger logfile;
ircserver serv;
char *buf;
commander cmd;
void *run( void *arg );
public:
void init(char *, ircserver, commander);
};