summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/chess.h5
-rw-r--r--mbbsd/chess.c43
2 files changed, 26 insertions, 22 deletions
diff --git a/include/chess.h b/include/chess.h
index d9284110..8384e225 100644
--- a/include/chess.h
+++ b/include/chess.h
@@ -164,10 +164,9 @@ typedef enum {
int ChessTimeCountDown(ChessInfo* info, int who, int length);
void ChessStepMade(ChessInfo* info, int who);
-ChessStepType ChessStepReceive(ChessInfo* info, void* step);
-int ChessStepSendOpposite(ChessInfo* info, const void* step);
-void ChessStepBroadcast(ChessInfo* info, const void* step);
+ChessStepType ChessStepReceive(ChessInfo* info, void* step); /* should this be public? */
int ChessStepSend(ChessInfo* info, const void* step);
+int ChessMessageSend(ChessInfo* info, ChessStepType type);
void ChessHistoryAppend(ChessInfo* info, void* step);
const void* ChessHistoryRetrieve(ChessInfo* info, int n);
diff --git a/mbbsd/chess.c b/mbbsd/chess.c
index 900b39c7..72632357 100644
--- a/mbbsd/chess.c
+++ b/mbbsd/chess.c
@@ -254,28 +254,17 @@ ChessSendMove(ChessInfo* info, int sock, const void *step)
return 1;
}
-ChessStepType
-ChessStepReceive(ChessInfo* info, void* step)
-{
- ChessStepType result = ChessRecvMove(info, info->sock, step);
-
- /* automatical routing */
- if (result != CHESS_STEP_FAILURE)
- ChessStepBroadcast(info, step);
-
- /* and logging */
- if (result == CHESS_STEP_NORMAL)
- ChessHistoryAppend(info, step);
-
- return result;
-}
-
-int
+inline static int
ChessStepSendOpposite(ChessInfo* info, const void* step)
{
void (*orig_handler)(int);
int result = 1;
-
+
+ /* fd 0 is the socket to user, it means no oppisite available.
+ * (Might be personal play) */
+ if (info->sock == 0)
+ return 1;
+
orig_handler = Signal(SIGPIPE, SIG_IGN);
if (!ChessSendMove(info, info->sock, step))
@@ -285,7 +274,7 @@ ChessStepSendOpposite(ChessInfo* info, const void* step)
return result;
}
-void
+inline static void
ChessStepBroadcast(ChessInfo* info, const void *step)
{
ChessBroadcastListNode *p = &(info->broadcast_list.head);
@@ -325,6 +314,22 @@ ChessMessageSend(ChessInfo* info, ChessStepType type)
return ChessStepSend(info, &type);
}
+ChessStepType
+ChessStepReceive(ChessInfo* info, void* step)
+{
+ ChessStepType result = ChessRecvMove(info, info->sock, step);
+
+ /* automatical routing */
+ if (result != CHESS_STEP_FAILURE)
+ ChessStepBroadcast(info, step);
+
+ /* and logging */
+ if (result == CHESS_STEP_NORMAL)
+ ChessHistoryAppend(info, step);
+
+ return result;
+}
+
inline static void
ChessReplayUntil(ChessInfo* info, int n)
{