mirror of https://git.lain.church/x3/caniadd.git
C-c handling + 1 todo
This commit is contained in:
parent
f315b481ac
commit
073340f0b8
|
@ -40,4 +40,5 @@ make
|
||||||
- After some time passes between now and cache moddate and it's not watched, then query and update it
|
- After some time passes between now and cache moddate and it's not watched, then query and update it
|
||||||
- Update cache entry is modify is used
|
- Update cache entry is modify is used
|
||||||
- Pretty hashing with color and progress bars and the other fancy stuff
|
- Pretty hashing with color and progress bars and the other fancy stuff
|
||||||
|
- Keep track of files not in AniDB. Maybe with a NULL lid?
|
||||||
- Write -h page, and maybe a man page too
|
- Write -h page, and maybe a man page too
|
||||||
|
|
17
src/api.c
17
src/api.c
|
@ -446,7 +446,7 @@ static void api_ratelimit_sent()
|
||||||
clock_gettime(API_CLOCK, &api_last_packet);
|
clock_gettime(API_CLOCK, &api_last_packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void api_ratelimit()
|
static enum error api_ratelimit()
|
||||||
{
|
{
|
||||||
struct timespec ts = {0};
|
struct timespec ts = {0};
|
||||||
uint64_t msdiff, mswait;
|
uint64_t msdiff, mswait;
|
||||||
|
@ -457,7 +457,7 @@ static void api_ratelimit()
|
||||||
if (api_packet_count <= API_FREESEND) {
|
if (api_packet_count <= API_FREESEND) {
|
||||||
uio_debug("This packet is for free! Yay :D (%d/%d)",
|
uio_debug("This packet is for free! Yay :D (%d/%d)",
|
||||||
api_packet_count, API_FREESEND);
|
api_packet_count, API_FREESEND);
|
||||||
return;
|
return NOERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
clock_gettime(API_CLOCK, &ts);
|
clock_gettime(API_CLOCK, &ts);
|
||||||
|
@ -465,7 +465,7 @@ static void api_ratelimit()
|
||||||
uio_debug("Time since last packet: %ld ms", msdiff);
|
uio_debug("Time since last packet: %ld ms", msdiff);
|
||||||
|
|
||||||
if (msdiff >= msrate)
|
if (msdiff >= msrate)
|
||||||
return; /* No ratelimiting is needed */
|
return NOERR; /* No ratelimiting is needed */
|
||||||
|
|
||||||
/* Need ratelimit, so do it here for now */
|
/* Need ratelimit, so do it here for now */
|
||||||
mswait = msrate - msdiff;
|
mswait = msrate - msdiff;
|
||||||
|
@ -473,11 +473,15 @@ static void api_ratelimit()
|
||||||
|
|
||||||
MS_TO_TIMESPEC_L(ts, mswait);
|
MS_TO_TIMESPEC_L(ts, mswait);
|
||||||
if (nanosleep(&ts, NULL) == -1) {
|
if (nanosleep(&ts, NULL) == -1) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR) {
|
||||||
uio_error("Nanosleep got interrupted");
|
uio_error("Nanosleep got interrupted");
|
||||||
else
|
return ERR_SHOULD_EXIT;
|
||||||
|
} else {
|
||||||
uio_error("Nanosleep failed");
|
uio_error("Nanosleep failed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NOERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -489,7 +493,8 @@ static ssize_t api_send(char *buffer, size_t data_len, size_t buf_size)
|
||||||
ssize_t read_len;
|
ssize_t read_len;
|
||||||
int en;
|
int en;
|
||||||
|
|
||||||
api_ratelimit();
|
if (api_ratelimit() == ERR_SHOULD_EXIT)
|
||||||
|
return -2;
|
||||||
uio_debug("{Api}: Sending: %.*s", (int)data_len, buffer);
|
uio_debug("{Api}: Sending: %.*s", (int)data_len, buffer);
|
||||||
if (api_encryption)
|
if (api_encryption)
|
||||||
data_len = api_encrypt(buffer, data_len);
|
data_len = api_encrypt(buffer, data_len);
|
||||||
|
|
|
@ -103,6 +103,11 @@ static enum error cmd_add_apisend(const char *path, const uint8_t *hash,
|
||||||
free(x->other);
|
free(x->other);
|
||||||
return NOERR;
|
return NOERR;
|
||||||
}
|
}
|
||||||
|
if (r.code == APICODE_NO_SUCH_FILE) {
|
||||||
|
uio_error("This file does not exists in the AniDB databse: %s",
|
||||||
|
path);
|
||||||
|
return NOERR;
|
||||||
|
}
|
||||||
if (r.code != APICODE_MYLIST_ENTRY_ADDED) {
|
if (r.code != APICODE_MYLIST_ENTRY_ADDED) {
|
||||||
uio_error("Mylistadd failure: %hu", r.code);
|
uio_error("Mylistadd failure: %hu", r.code);
|
||||||
return ERR_CMD_FAILED;
|
return ERR_CMD_FAILED;
|
||||||
|
|
Loading…
Reference in New Issue