@@ -92,14 +92,86 @@ void connect_statement(struct basic_ctx* ctx);
9292 */
9393void sockread_statement (struct basic_ctx * ctx );
9494
95+ /**
96+ * @brief Process the UDPWRITE statement in BASIC.
97+ *
98+ * Sends a single UDP datagram to the specified destination address and port, optionally binding a source port.
99+ * Arguments are parsed from the BASIC statement and validated; on error a diagnostic is raised to the tokenizer.
100+ *
101+ * @param ctx BASIC context.
102+ */
95103void udpwrite_statement (struct basic_ctx * ctx );
96104
105+ /**
106+ * @brief Process the UDPBIND statement in BASIC.
107+ *
108+ * Binds a UDP “daemon” handler for the given local port so that inbound datagrams are queued for subsequent reads.
109+ * The handler stores packets in a per-port FIFO owned by the BASIC runtime.
110+ *
111+ * @param ctx BASIC context.
112+ */
97113void udpbind_statement (struct basic_ctx * ctx );
98114
115+ /**
116+ * @brief Process the UDPUNBIND statement in BASIC.
117+ *
118+ * Unregisters a previously bound UDP handler for the given local port and stops queueing packets for that port.
119+ *
120+ * @param ctx BASIC context.
121+ */
99122void udpunbind_statement (struct basic_ctx * ctx );
100123
124+ /**
125+ * @brief Read the next queued UDP packet payload for a port.
126+ *
127+ * Implements UDPREAD$ in BASIC. Pops the oldest queued datagram for the specified local port and returns its
128+ * payload as a newly allocated string. Side effects: updates the BASIC context’s “last packet” metadata
129+ * (source IP/port, length).
130+ *
131+ * @param ctx BASIC context.
132+ * @return Pointer to a NUL-terminated payload string (owned by the BASIC GC), or an empty string if no packet
133+ * is available.
134+ */
101135char * basic_udpread (struct basic_ctx * ctx );
102136
137+ /**
138+ * @brief Return the source port of the last UDP packet read.
139+ *
140+ * Exposes the metadata captured by the most recent successful UDPREAD$ call.
141+ *
142+ * @param ctx BASIC context.
143+ * @return Source UDP port number of the last packet, or 0 if no packet has been read.
144+ */
103145int64_t basic_udplastsourceport (struct basic_ctx * ctx );
104146
147+ /**
148+ * @brief Return the source IP address of the last UDP packet read.
149+ *
150+ * Exposes the metadata captured by the most recent successful UDPREAD$ call.
151+ *
152+ * @param ctx BASIC context.
153+ * @return Source IPv4 address as a dotted-quad string, or an empty string if no packet has been read.
154+ */
105155char * basic_udplastip (struct basic_ctx * ctx );
156+
157+ /**
158+ * @brief Create a listening TCP socket from BASIC.
159+ *
160+ * Implements SOCKLISTEN. Binds a TCP listener to the specified address and port with the requested backlog and
161+ * returns a file descriptor for subsequent SOCKACCEPT calls.
162+ *
163+ * @param ctx BASIC context.
164+ * @return Non-negative file descriptor on success; −1 with an error raised into the tokenizer on failure.
165+ */
166+ int64_t basic_socklisten (struct basic_ctx * ctx );
167+
168+ /**
169+ * @brief Accept an incoming TCP connection from BASIC (non-blocking).
170+ *
171+ * Implements SOCKACCEPT. If an established connection is queued, returns a new file descriptor; if no
172+ * connection is currently ready, returns −1 without blocking. Errors are reported to the tokenizer.
173+ *
174+ * @param ctx BASIC context.
175+ * @return File descriptor of the accepted connection, or −1 if no connection is ready or on error.
176+ */
177+ int64_t basic_sockaccept (struct basic_ctx * ctx );
0 commit comments