These calls return the number of bytes received, or -1 if an error occurred. The return value will be 0 when the peer has performed an orderly shutdown.
ssize_t recvd = recv(ClientSocket, buffer, MESSAGE_MAXLEN, 0);
if (recvd != SOCKET_ERROR)
{
// recv не возвращает ошибку
printf("server response: %.*s\n", recvd, buffer); // напечатает только то, что было принято
}
else
{
error = WSAGetLastError();
printf("recv failed: %d\n", error);
}
Я хочу произвести отладку и остановить программу когда будет соблюдаться определенное условие. Допустим сумма регистров eax+ebx будет равна 65463.
$ cat > main.c
int v;
static void f(int *p)
{
int i;
for (i = 0; i < 20; ++i)
*p = (i - 10) * (i - 10);
}
int main()
{
f(&v);
return 0;
}
$ gcc -g2 -o watch main.c
$ gdb ./watch
...
Reading symbols from ./watch...done.
(gdb) start
Temporary breakpoint 1 at 0x4004ec: file main.c, line 13.
Starting program: /home/jcmvbkbc/tmp/toster/watch/watch
Temporary breakpoint 1, main () at main.c:13
13 f(&v);
(gdb) watch v
Hardware watchpoint 2: v
(gdb) commands
Type commands for breakpoint(s) 2, one per line.
End with a line saying just "end".
>if (v != 4)
>continue
>end
>end
(gdb) c
Continuing.
...
Hardware watchpoint 2: v
Old value = 9
New value = 4
f (p=0x600904 <v>) at main.c:7
7 for (i = 0; i < 20; ++i)
(gdb)
#include <limits.h>
#include <stdio.h>
#include <string.h>
#define N (sizeof(a) / sizeof(a[0]))
inline int sign(int d)
{
if (d == 0)
return 0;
return d < 0 ? -1 : 1;
}
inline int abs(int v)
{
return v < 0 ? -v : v;
}
int main()
{
int a[] = {2, 1, 3, 4, 0};
int q[N];
for (;;) {
int best_profit = INT_MIN;
int best_src = -1;
int best_dst = -1;
int i, src, dst, tmp;
for (i = 0; i < N; ++i)
q[i] = i - a[i];
for (src = 0; src < N; ++src)
for (dst = 0; dst < N; ++dst) {
int d = sign(dst - src);
int profit = abs(q[src]) - abs(q[src] + dst - src);
//printf("...%d -> %d: profit = %d", src, dst, profit);
for (i = src + d; i != dst + d; i += d) {
if (sign(q[i]) == d) {
++profit;
//printf(" + 1");
} else {
--profit;
//printf(" - 1");
}
}
//printf(" = %d\n", profit);
if (profit > best_profit) {
best_src = src;
best_dst = dst;
best_profit = profit;
//printf("... -- new best!\n");
}
}
printf("%d -> %d (profit = %d)\n", best_src, best_dst, best_profit);
if (best_profit == 0)
break;
tmp = a[best_src];
if (best_dst < best_src)
memmove(a + best_dst + 1, a + best_dst, (best_src - best_dst) * sizeof(int));
else
memmove(a + best_src, a + best_src + 1, (best_dst - best_src) * sizeof(int));
a[best_dst] = tmp;
for (i = 0; i < N; ++i)
printf("%d ", a[i]);
printf("\n");
}
return 0;
}
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
5 Reallocated_Sector_Ct 0x0032 100 100 000 Old_age Always - 2
9 Power_On_Hours_and_Msec 0x0032 000 000 000 Old_age Always - 916104h+32m+02.410s
12 Power_Cycle_Count 0x0032 098 098 000 Old_age Always - 2093
181 Program_Fail_Cnt_Total 0x0032 000 000 000 Old_age Always - 2
182 Erase_Fail_Count_Total 0x0032 000 000 000 Old_age Always - 0
192 Power-Off_Retract_Count 0x0032 100 100 000 Old_age Always - 2093
225 Host_Writes_32MiB 0x0032 100 100 000 Old_age Always - 658878
232 Available_Reservd_Space 0x0033 100 100 010 Pre-fail Always - 0
233 Media_Wearout_Indicator 0x0032 100 100 000 Old_age Always - 0
241 Host_Writes_32MiB 0x0032 100 100 000 Old_age Always - 658878
242 Host_Reads_32MiB 0x0032 100 100 000 Old_age Always - 561297
249 NAND_Writes_1GiB 0x0013 100 100 000 Pre-fail Always - 21915
А нет универсальной проверки на любую ошибку? Типо такого?
do-something || :
if ! do-something ; then
echo 'do-something failed'
fi
выдают одинаково верный результат
ответы в которых люди дают развернутые ответы и цитируют стандарт языка
Люди, которые знакомы с ней, непосредственно брали в руки документ и читали его от корки до корки? Или же это происходило в процесс практики
По идее я должен взять исходники библиотеки и прямо из Go указать пути к исходникам
На какие подводные камни я могу наткнутся при таком использовании?