Загрузить файлы в «C»
This commit is contained in:
parent
bfd92a19b7
commit
b0c07cdf38
3 changed files with 16 additions and 25 deletions
23
C/irc.c
23
C/irc.c
|
@ -16,6 +16,10 @@ unsigned int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int p
|
|||
if (irc->socket < 0)
|
||||
return IRCC_ERROR;
|
||||
|
||||
struct timeval tv = {IRCC_PING_TIMEOUT, 0};
|
||||
if (setsockopt(irc->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0)
|
||||
return IRCC_ERROR;
|
||||
|
||||
int status = connect(irc->socket, (struct sockaddr *)&client_str, sizeof(client_str));
|
||||
if (status == -1)
|
||||
return IRCC_ERROR;
|
||||
|
@ -59,12 +63,12 @@ void IRCC_parse(char *tmp, IRCC_client *irc){
|
|||
}
|
||||
|
||||
unsigned int IRCC_recv(IRCC_client *irc){
|
||||
memset(irc->raw, '\0', irc->size);
|
||||
memset(irc->raw, '\0', IRCC_MSG_MAX);
|
||||
irc->channel = NULL;
|
||||
irc->msg = NULL;
|
||||
irc->nick = NULL;
|
||||
|
||||
int msg_size = recv(irc->socket, irc->raw, irc->size, 0);
|
||||
int msg_size = recv(irc->socket, irc->raw, IRCC_MSG_MAX, 0);
|
||||
if (msg_size == 0 || msg_size == -1)
|
||||
return IRCC_DISCONNECTED;
|
||||
|
||||
|
@ -117,7 +121,7 @@ unsigned int IRCC_recv(IRCC_client *irc){
|
|||
return IRCC_SUCCESS;
|
||||
}
|
||||
|
||||
void IRCC_send(IRCC_client *irc, char *msg, char *channel){
|
||||
void IRCC_send(IRCC_client *irc, const char *msg, const char *channel){
|
||||
size_t size = strlen("PRIVMSG :\r\n") + strlen(channel) + strlen(msg);
|
||||
|
||||
char *tmp = (char *)malloc(size + 1);
|
||||
|
@ -133,21 +137,14 @@ void IRCC_send(IRCC_client *irc, char *msg, char *channel){
|
|||
free(tmp);
|
||||
}
|
||||
|
||||
unsigned int IRCC_init(IRCC_client *irc, size_t size){
|
||||
if (size <= 250){
|
||||
fprintf(stderr, "Low buffer size (IRCC_init) (Min 250/512)\n");
|
||||
return IRCC_ERROR;
|
||||
}
|
||||
|
||||
irc->raw = (char *)malloc(size + 1);
|
||||
unsigned int IRCC_init(IRCC_client *irc) {
|
||||
irc->raw = (char *)malloc(IRCC_MSG_MAX + 1);
|
||||
if (irc->raw == NULL){
|
||||
fprintf(stderr, "malloc returned NULL (IRCC_init)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
irc->msg = irc->nick = irc->channel = NULL;
|
||||
|
||||
irc->size = size;
|
||||
return IRCC_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -156,6 +153,4 @@ void IRCC_close(IRCC_client *irc){
|
|||
|
||||
free(irc->raw);
|
||||
irc->raw = irc->msg = irc->nick = irc->channel = NULL;
|
||||
|
||||
irc->size = 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue