Socket.st
changeset 888 a868b0e54a2b
parent 887 2b2dc6b59b5a
child 896 2ca43149a20e
equal deleted inserted replaced
887:2b2dc6b59b5a 888:a868b0e54a2b
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
       
    12 
       
    13 "{ Package: 'stx:libbasic2' }"
    12 
    14 
    13 NonPositionableExternalStream subclass:#Socket
    15 NonPositionableExternalStream subclass:#Socket
    14 	instanceVariableNames:'domain socketType protocol port serviceName peerName'
    16 	instanceVariableNames:'domain socketType protocol port serviceName peerName'
    15 	classVariableNames:''
    17 	classVariableNames:''
    16 	poolDictionaries:''
    18 	poolDictionaries:''
  2243     int n;
  2245     int n;
  2244     char *cp;
  2246     char *cp;
  2245     int flags = 0;
  2247     int flags = 0;
  2246 
  2248 
  2247     if (fp != nil) {
  2249     if (fp != nil) {
  2248 	sock = fileno(__FILEVal(fp));
  2250         sock = fileno(__FILEVal(fp));
  2249 
  2251 
  2250 	oClass = __Class(aDataBuffer);
  2252         oClass = __Class(aDataBuffer);
  2251 	switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
  2253         switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
  2252 	    case BYTEARRAY:
  2254             case BYTEARRAY:
  2253 	    case WORDARRAY:
  2255             case WORDARRAY:
  2254 	    case SWORDARRAY:
  2256             case SWORDARRAY:
  2255 	    case LONGARRAY:
  2257             case LONGARRAY:
  2256 	    case SLONGARRAY:
  2258             case SLONGARRAY:
  2257 	    case FLOATARRAY:
  2259             case FLOATARRAY:
  2258 	    case DOUBLEARRAY:
  2260             case DOUBLEARRAY:
  2259 		break;
  2261                 break;
  2260 	    default:
  2262             default:
  2261 		goto bad;
  2263                 goto bad;
  2262 	}
  2264         }
  2263 
  2265 
  2264 	nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
  2266         nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
  2265 	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
  2267         nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
  2266 	objSize = _Size(aDataBuffer) - nInstBytes;
  2268         objSize = _Size(aDataBuffer) - nInstBytes;
  2267 	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
  2269         cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
  2268 	if (__isSmallInteger(startIndex)) {
  2270         if (__isSmallInteger(startIndex)) {
  2269 	    cp += __intVal(startIndex);
  2271             cp += __intVal(startIndex);
  2270 	    objSize -= __intVal(startIndex);
  2272             objSize -= __intVal(startIndex);
  2271 	}
  2273         }
  2272 	if (__isSmallInteger(nBytes)) {
  2274         if (__isSmallInteger(nBytes)) {
  2273 	    if (__intVal(nBytes) < objSize) {
  2275             if (__intVal(nBytes) < objSize) {
  2274 		objSize = __intVal(nBytes);
  2276                 objSize = __intVal(nBytes);
  2275 	    }
  2277             }
  2276 	}
  2278         }
  2277 
  2279 
  2278 	__BEGIN_INTERRUPTABLE__
  2280         __BEGIN_INTERRUPTABLE__
  2279 	do {
  2281         do {
  2280 	    if (addrBytes == nil) {
  2282             if (addrBytes == nil) {
  2281 		n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) 0, 0);
  2283                 n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) 0, 0);
  2282 	    } else {
  2284             } else {
  2283 		n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) &sa, &alen);
  2285                 n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) &sa, &alen);
  2284 	    }
  2286             }
  2285 	} while ((n < 0) && (errno == EINTR));
  2287         } while ((n < 0) && (errno == EINTR));
  2286 	__END_INTERRUPTABLE__
  2288         __END_INTERRUPTABLE__
  2287 
  2289 
  2288 	if (n >= 0) {
  2290         if (n >= 0) {
  2289 	    if (addrBytes != nil) {
  2291             if (addrBytes != nil) {
  2290 		oClass = __Class(addrBytes);
  2292                 oClass = __Class(addrBytes);
  2291 		if ((_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) != BYTEARRAY) 
  2293                 if ((_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) != BYTEARRAY) 
  2292 		    goto bad;
  2294                     goto bad;
  2293 		nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
  2295                 nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
  2294 		nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
  2296                 nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
  2295 		objSize = _Size(addrBytes) - nInstBytes;
  2297                 objSize = _Size(addrBytes) - nInstBytes;
  2296 		cp = (char *)__InstPtr(addrBytes) + nInstBytes;
  2298                 cp = (char *)__InstPtr(addrBytes) + nInstBytes;
  2297 		if (objSize < alen) 
  2299                 if (objSize < alen) 
  2298 		    goto bad;
  2300                     goto bad;
  2299 
  2301 
  2300 		myDomain = __INST(domain);
  2302                 myDomain = __INST(domain);
  2301 
  2303 
  2302 		/*
  2304                 /*
  2303 		 * extract the datagrams address
  2305                  * extract the datagrams address
  2304 		 */
  2306                  */
  2305 # ifdef AF_INET
  2307 # ifdef AF_INET
  2306 		if (myDomain == @symbol(inet)) {
  2308                 if (myDomain == @symbol(inet)) {
  2307 		    if (objSize < 4) 
  2309                     if (objSize < 4) 
  2308 			goto bad;
  2310                         goto bad;
  2309 		    cp[0] = (sa.in.sin_addr.s_addr >> 24) & 0xFF;
  2311                     cp[0] = (sa.in.sin_addr.s_addr >> 24) & 0xFF;
  2310 		    cp[2] = (sa.in.sin_addr.s_addr >> 16) & 0xFF;
  2312                     cp[2] = (sa.in.sin_addr.s_addr >> 16) & 0xFF;
  2311 		    cp[3] = (sa.in.sin_addr.s_addr >> 8) & 0xFF;
  2313                     cp[3] = (sa.in.sin_addr.s_addr >> 8) & 0xFF;
  2312 		    cp[4] = (sa.in.sin_addr.s_addr >> 0) & 0xFF;
  2314                     cp[4] = (sa.in.sin_addr.s_addr >> 0) & 0xFF;
  2313 		    alen = 4;
  2315                     alen = 4;
  2314 		}
  2316                 }
  2315 # endif /* AF_INET */
  2317 # endif /* AF_INET */
  2316 
  2318 
  2317 # ifdef AF_INET6
  2319 # ifdef AF_INET6
  2318 		if (myDomain == @symbol(inet6)) {
  2320                 if (myDomain == @symbol(inet6)) {
  2319 		    if (objSize < sizeof(sa.in6.sin6_addr.s6_addr)) 
  2321                     if (objSize < sizeof(sa.in6.sin6_addr.s6_addr)) 
  2320 			goto bad;
  2322                         goto bad;
  2321 		    bcopy(sa.in6.sin6_addr.s6_addr, cp, sizeof(sa.in6.sin6_addr.s6_addr));
  2323                     bcopy(sa.in6.sin6_addr.s6_addr, cp, sizeof(sa.in6.sin6_addr.s6_addr));
  2322 		    alen = sizeof(sa.in6.sin6_addr.s6_addr);
  2324                     alen = sizeof(sa.in6.sin6_addr.s6_addr);
  2323 		}
  2325                 }
  2324 # endif /* AF_INET6 */
  2326 # endif /* AF_INET6 */
  2325 
  2327 
  2326 # ifdef AF_APPLETALK
  2328 # ifdef AF_APPLETALK
  2327 		if (myDomain == @symbol(appletalk)) {
  2329                 if (myDomain == @symbol(appletalk)) {
  2328 		    if (objSize < 3) 
  2330                     if (objSize < 3) 
  2329 			goto bad;
  2331                         goto bad;
  2330 		    cp[0] = (sa.at.sat_addr.s_net >> 8) & 0xFF;
  2332                     cp[0] = (sa.at.sat_addr.s_net >> 8) & 0xFF;
  2331 		    cp[2] = (sa.at.sat_addr.s_net) & 0xFF;
  2333                     cp[2] = (sa.at.sat_addr.s_net) & 0xFF;
  2332 		    cp[3] = (sa.at.sat_addr.s_node) & 0xFF;
  2334                     cp[3] = (sa.at.sat_addr.s_node) & 0xFF;
  2333 		    alen = 3;
  2335                     alen = 3;
  2334 		}
  2336                 }
  2335 # endif /* AF_APPLETALK */
  2337 # endif /* AF_APPLETALK */
  2336 
  2338 
  2337 		/*
  2339                 /*
  2338 		 * XXXX add addressing stuff for other domains here ...
  2340                  * XXXX add addressing stuff for other domains here ...
  2339 		 */
  2341                  */
  2340 # ifdef AF_X25
  2342 # ifdef AF_X25
  2341 		if (myDomain == @symbol(x25)) {
  2343                 if (myDomain == @symbol(x25)) {
  2342 		}
  2344                 }
  2343 # endif
  2345 # endif
  2344 
  2346 
  2345 # ifdef AF_AX25
  2347 # ifdef AF_AX25
  2346 		if (myDomain == @symbol(ax25)) {
  2348                 if (myDomain == @symbol(ax25)) {
  2347 		}
  2349                 }
  2348 # endif
  2350 # endif
  2349 
  2351 
  2350 # ifdef AF_NS
  2352 # ifdef AF_NS
  2351 		if ((myDomain == @symbol(ns)) 
  2353                 if ((myDomain == @symbol(ns)) 
  2352 		 || (myDomain == @symbol(xns))) {
  2354                  || (myDomain == @symbol(xns))) {
  2353 		}
  2355                 }
  2354 # endif
  2356 # endif
  2355 
  2357 
  2356 # ifdef AF_SNA
  2358 # ifdef AF_SNA
  2357 		if (myDomain == @symbol(sna)) {
  2359                 if (myDomain == @symbol(sna)) {
  2358 		}
  2360                 }
  2359 # endif
  2361 # endif
  2360 
  2362 
  2361 # ifdef AF_RAW
  2363 # ifdef AF_RAW
  2362 		if (myDomain == @symbol(raw)) {
  2364                 if (myDomain == @symbol(raw)) {
  2363 		}
  2365                 }
  2364 # endif
  2366 # endif
  2365 
  2367 
  2366 # ifdef AF_ISO
  2368 # ifdef AF_ISO
  2367 		if (myDomain == @symbol(iso)) {
  2369                 if (myDomain == @symbol(iso)) {
  2368 		}
  2370                 }
  2369 # endif
  2371 # endif
  2370 
  2372 
  2371 # ifdef AF_DECnet
  2373 # ifdef AF_DECnet
  2372 		if (myDomain == @symbol(decnet)) {
  2374                 if (myDomain == @symbol(decnet)) {
  2373 		}
  2375                 }
  2374 # endif
  2376 # endif
  2375 
  2377 
  2376 # ifdef AF_NETBIOS
  2378 # ifdef AF_NETBIOS
  2377 		if (myDomain == @symbol(netbios)) {
  2379                 if (myDomain == @symbol(netbios)) {
  2378 		}
  2380                 }
  2379 # endif
  2381 # endif
  2380 
  2382 
  2381 # ifdef AF_IPX
  2383 # ifdef AF_IPX
  2382 		if (myDomain == @symbol(ipx)) {
  2384                 if (myDomain == @symbol(ipx)) {
  2383 		}
  2385                 }
  2384 # endif
  2386 # endif
  2385 
  2387 
  2386 # ifdef AF_BRIDGE
  2388 # ifdef AF_BRIDGE
  2387 		if (myDomain == @symbol(bridge)) {
  2389                 if (myDomain == @symbol(bridge)) {
  2388 		}
  2390                 }
  2389 # endif
  2391 # endif
  2390 
  2392 
  2391 # ifdef AF_BSC
  2393 # ifdef AF_BSC
  2392 		if (myDomain == @symbol(bsc)) {
  2394                 if (myDomain == @symbol(bsc)) {
  2393 		}
  2395                 }
  2394 # endif
  2396 # endif
  2395 
  2397 
  2396 # ifdef AF_ROSE
  2398 # ifdef AF_ROSE
  2397 		if (myDomain == @symbol(rose)) {
  2399                 if (myDomain == @symbol(rose)) {
  2398 		}
  2400                 }
  2399 # endif
  2401 # endif
  2400 
  2402 
  2401 # ifdef AF_IRDA
  2403 # ifdef AF_IRDA
  2402 		if (myDomain == @symbol(irda)) {
  2404                 if (myDomain == @symbol(irda)) {
  2403 		}
  2405                 }
  2404 # endif
  2406 # endif
  2405 
  2407 
  2406 # if defined(AF_CCITT) && (AF_CCITT != AF_X25)
  2408 # if defined(AF_CCITT) && (AF_CCITT != AF_X25)
  2407 		if (myDomain == @symbol(ccitt)) {
  2409                 if (myDomain == @symbol(ccitt)) {
  2408 		}
  2410                 }
  2409 # endif
  2411 # endif
  2410 
  2412 
  2411 		addrLen = __MKSMALLINT(alen);
  2413                 addrLen = __MKSMALLINT(alen);
  2412 	    }
  2414             }
  2413 	}
  2415         }
  2414 	if (n < 0) {
  2416         if (n < 0) {
  2415 	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
  2417             __INST(lastErrorNumber) = __MKSMALLINT(errno);
  2416 	}
  2418         }
  2417 	nReceived = __MKSMALLINT(n);
  2419         nReceived = __MKSMALLINT(n);
  2418     }
  2420     }
  2419 #endif
  2421 #endif
  2420 bad: ;
  2422 bad: ;
  2421 %}.
  2423 %}.
  2422     nReceived notNil ifTrue:[
  2424     nReceived notNil ifTrue:[
  2423 	nReceived < 0 ifTrue:[
  2425         nReceived < 0 ifTrue:[
  2424 	    'Socket [warning]: ' infoPrint.
  2426             'Socket [warning]: ' infoPrint.
  2425 	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
  2427             (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
  2426 	].
  2428         ].
  2427 	addrLen notNil ifTrue:[
  2429         addrLen notNil ifTrue:[
  2428 	    anAddressBuffer class isBytes ifTrue:[
  2430            (anAddressBuffer isKindOf:SocketAddress) ifFalse:[
  2429 		"/ can be a ByteArray for ST/X compatibility
  2431                 "/ can be a ByteArray for ST/X compatibility
  2430 		anAddressBuffer replaceFrom:1 to:addrLen with:addrBytes
  2432                 anAddressBuffer replaceFrom:1 to:addrLen with:addrBytes
  2431 	    ] ifFalse:[
  2433             ] ifTrue:[
  2432 		"/ can be a SocketAddress for ST-80 compatibility
  2434                 "/ can be a SocketAddress for ST-80 compatibility
  2433 		anAddressBuffer hostAddress:(addrBytes copyTo:addrLen)
  2435                 anAddressBuffer hostAddress:(addrBytes copyTo:addrLen)
  2434 	    ].
  2436             ].
  2435 	].
  2437         ].
  2436 	^ nReceived
  2438         ^ nReceived
  2437     ].
  2439     ].
  2438     "
  2440     "
  2439      arrive here if you try to receive into an invalid buffer
  2441      arrive here if you try to receive into an invalid buffer
  2440      (i.e. not ByteArray-like), 
  2442      (i.e. not ByteArray-like), 
  2441      or if the addressBuffer is nonNil AND not a ByteArray/String 
  2443      or if the addressBuffer is nonNil AND not a ByteArray/String 
  2483     |addrBytes addrLen nReceived portNo|
  2485     |addrBytes addrLen nReceived portNo|
  2484 
  2486 
  2485     "/ addressBuffer can be a byteArray (last 2 bytes are portNo, msb-first)
  2487     "/ addressBuffer can be a byteArray (last 2 bytes are portNo, msb-first)
  2486     "/ or (better) an instance of SocketAddress
  2488     "/ or (better) an instance of SocketAddress
  2487     "/
  2489     "/
  2488     anAddressBuffer class isBytes ifTrue:[
  2490     (anAddressBuffer isKindOf:SocketAddress) ifFalse:[
  2489 	domain == #inet ifTrue:[
  2491         domain == #inet ifTrue:[
  2490 	    addrBytes := anAddressBuffer copyFrom:1 to:4.
  2492             addrBytes := anAddressBuffer copyFrom:1 to:4.
  2491 	    portNo := ((anAddressBuffer at:5) bitShift:8)
  2493             portNo := ((anAddressBuffer at:5) bitShift:8)
  2492 		      + (anAddressBuffer at:6).
  2494                       + (anAddressBuffer at:6).
  2493 	] ifFalse:[
  2495         ] ifFalse:[
  2494 	    domain == #appletalk ifTrue:[
  2496             domain == #appletalk ifTrue:[
  2495 		addrBytes := anAddressBuffer copyFrom:1 to:3.
  2497                 addrBytes := anAddressBuffer copyFrom:1 to:3.
  2496 		portNo := ((anAddressBuffer at:5) bitShift:8)
  2498                 portNo := ((anAddressBuffer at:5) bitShift:8)
  2497 			  + (anAddressBuffer at:6).
  2499                           + (anAddressBuffer at:6).
  2498 	    ].
  2500             ].
  2499 	].
  2501         ].
  2500     ] ifFalse:[
  2502     ] ifTrue:[
  2501 	addrBytes := anAddressBuffer hostAddress.
  2503         addrBytes := anAddressBuffer hostAddress.
  2502 	portNo := anAddressBuffer port.
  2504         portNo := anAddressBuffer port.
  2503     ].
  2505     ].
  2504 %{
  2506 %{
  2505 #ifndef NO_SOCKET
  2507 #ifndef NO_SOCKET
  2506     OBJ oClass;
  2508     OBJ oClass;
  2507     OBJ fp = __INST(filePointer);
  2509     OBJ fp = __INST(filePointer);
  2519     _flags = __longIntVal(flags);
  2521     _flags = __longIntVal(flags);
  2520  
  2522  
  2521     if ((fp != nil) 
  2523     if ((fp != nil) 
  2522      && __isSmallInteger(startIndex)
  2524      && __isSmallInteger(startIndex)
  2523      && __isSmallInteger(count)) {
  2525      && __isSmallInteger(count)) {
  2524 	sock = fileno(__FILEVal(fp));
  2526         sock = fileno(__FILEVal(fp));
  2525 
  2527 
  2526 	if (addrBytes == nil) {
  2528         if (addrBytes == nil) {
  2527 	    alen = 0;
  2529             alen = 0;
  2528 	    saPtr = (struct sockaddr *)0;
  2530             saPtr = (struct sockaddr *)0;
  2529 	} else {
  2531         } else {
  2530 	    if (! __isByteArray(addrBytes)) goto bad;
  2532             if (! __isByteArray(addrBytes)) goto bad;
  2531 
  2533 
  2532 	    cp = (char *)__ByteArrayInstPtr(addrBytes)->ba_element;
  2534             cp = (char *)__ByteArrayInstPtr(addrBytes)->ba_element;
  2533 	    n = __byteArraySize(addrBytes);
  2535             n = __byteArraySize(addrBytes);
  2534 	    if (alen < n) n = alen;
  2536             if (alen < n) n = alen;
  2535 # ifdef DGRAM_DEBUG
  2537 # ifdef DGRAM_DEBUG
  2536 	    printf("address is %d bytes ... %d.%d.%d.%d", n, cp[0], cp[1], cp[2], cp[3]);
  2538             printf("address is %d bytes ... %d.%d.%d.%d", n, cp[0], cp[1], cp[2], cp[3]);
  2537 # endif
  2539 # endif
  2538 	    bcopy(cp, &sa.in.sin_addr.s_addr, n);
  2540             bcopy(cp, &sa.in.sin_addr.s_addr, n);
  2539 
  2541 
  2540 # ifdef AF_INET
  2542 # ifdef AF_INET
  2541 	    if (__INST(domain) == @symbol(inet)) {
  2543             if (__INST(domain) == @symbol(inet)) {
  2542 		sa.in.sin_family = AF_INET;
  2544                 sa.in.sin_family = AF_INET;
  2543 		sa.in.sin_port = htons((u_short) __intVal(portNo)); 
  2545                 sa.in.sin_port = htons((u_short) __intVal(portNo)); 
  2544 	    }
  2546             }
  2545 # endif
  2547 # endif
  2546 # ifdef AF_INET6
  2548 # ifdef AF_INET6
  2547 	    if (__INST(domain) == @symbol(inet6)) {
  2549             if (__INST(domain) == @symbol(inet6)) {
  2548 		sa.in6.sin6_family = AF_INET6;
  2550                 sa.in6.sin6_family = AF_INET6;
  2549 		sa.in6.sin6_port = htons((u_short) __intVal(portNo)); 
  2551                 sa.in6.sin6_port = htons((u_short) __intVal(portNo)); 
  2550 	    }
  2552             }
  2551 # endif
  2553 # endif
  2552 # ifdef AF_APPLETALK
  2554 # ifdef AF_APPLETALK
  2553 	    if (__INST(domain) == @symbol(appletalk)) {
  2555             if (__INST(domain) == @symbol(appletalk)) {
  2554 		sa.at.sat_family = AF_APPLETALK;
  2556                 sa.at.sat_family = AF_APPLETALK;
  2555 		sa.at.sat_port = __intVal(portNo);
  2557                 sa.at.sat_port = __intVal(portNo);
  2556 	    }
  2558             }
  2557 # endif
  2559 # endif
  2558 # ifdef AF_IRDA
  2560 # ifdef AF_IRDA
  2559 	    if (__INST(domain) == @symbol(irda)) {
  2561             if (__INST(domain) == @symbol(irda)) {
  2560 	    }
  2562             }
  2561 # endif
  2563 # endif
  2562 	}
  2564         }
  2563 
  2565 
  2564 	oClass = __Class(aDataBuffer);
  2566         oClass = __Class(aDataBuffer);
  2565 	switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
  2567         switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
  2566 	    case BYTEARRAY:
  2568             case BYTEARRAY:
  2567 		offs = __intVal(startIndex) - 1;
  2569                 offs = __intVal(startIndex) - 1;
  2568 		break;
  2570                 break;
  2569 	    case WORDARRAY:
  2571             case WORDARRAY:
  2570 	    case SWORDARRAY:
  2572             case SWORDARRAY:
  2571 		offs = (__intVal(startIndex) - 1) * 2;
  2573                 offs = (__intVal(startIndex) - 1) * 2;
  2572 		break;
  2574                 break;
  2573 	    case LONGARRAY:
  2575             case LONGARRAY:
  2574 	    case SLONGARRAY:
  2576             case SLONGARRAY:
  2575 		offs = (__intVal(startIndex) - 1) * 4;
  2577                 offs = (__intVal(startIndex) - 1) * 4;
  2576 		break;
  2578                 break;
  2577 	    case LONGLONGARRAY:
  2579             case LONGLONGARRAY:
  2578 	    case SLONGLONGARRAY:
  2580             case SLONGLONGARRAY:
  2579 		offs = (__intVal(startIndex) - 1) * 8;
  2581                 offs = (__intVal(startIndex) - 1) * 8;
  2580 # ifdef __NEED_LONGLONG_ALIGN
  2582 # ifdef __NEED_LONGLONG_ALIGN
  2581 		offs += 4;
  2583                 offs += 4;
  2582 # endif
  2584 # endif
  2583 	    case FLOATARRAY:
  2585             case FLOATARRAY:
  2584 		offs = (__intVal(startIndex) - 1) * sizeof(float);
  2586                 offs = (__intVal(startIndex) - 1) * sizeof(float);
  2585 		break;
  2587                 break;
  2586 	    case DOUBLEARRAY:
  2588             case DOUBLEARRAY:
  2587 		offs = (__intVal(startIndex) - 1) * sizeof(double);
  2589                 offs = (__intVal(startIndex) - 1) * sizeof(double);
  2588 # ifdef __NEED_DOUBLE_ALIGN
  2590 # ifdef __NEED_DOUBLE_ALIGN
  2589 		offs += 4;
  2591                 offs += 4;
  2590 # endif
  2592 # endif
  2591 		break;
  2593                 break;
  2592 	    default:
  2594             default:
  2593 		goto bad;
  2595                 goto bad;
  2594 	}
  2596         }
  2595 	nBytes = __intVal(count);
  2597         nBytes = __intVal(count);
  2596 
  2598 
  2597 	nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
  2599         nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
  2598 	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
  2600         nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
  2599 	objSize = __qSize(aDataBuffer) - nInstBytes;
  2601         objSize = __qSize(aDataBuffer) - nInstBytes;
  2600 	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
  2602         cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
  2601 	cp += offs;
  2603         cp += offs;
  2602 	if ((offs + nBytes) > objSize) {
  2604         if ((offs + nBytes) > objSize) {
  2603 # ifdef DGRAM_DEBUG
  2605 # ifdef DGRAM_DEBUG
  2604 	    printf("cut off ...\n");
  2606             printf("cut off ...\n");
  2605 # endif
  2607 # endif
  2606 	    nBytes = objSize - offs;
  2608             nBytes = objSize - offs;
  2607 	}
  2609         }
  2608 
  2610 
  2609 	norder = htonl(sa.in.sin_addr.s_addr);
  2611         norder = htonl(sa.in.sin_addr.s_addr);
  2610 # ifdef DGRAM_DEBUG
  2612 # ifdef DGRAM_DEBUG
  2611 	printf("sending %d bytes ... to ", nBytes);
  2613         printf("sending %d bytes ... to ", nBytes);
  2612 	printf("%d.%d.%d.%d\n",
  2614         printf("%d.%d.%d.%d\n",
  2613 		    (norder >> 24) & 0xFF,
  2615                     (norder >> 24) & 0xFF,
  2614 		    (norder >> 16) & 0xFF,
  2616                     (norder >> 16) & 0xFF,
  2615 		    (norder >> 8) & 0xFF,
  2617                     (norder >> 8) & 0xFF,
  2616 		    norder & 0xFF);
  2618                     norder & 0xFF);
  2617 # endif
  2619 # endif
  2618 
  2620 
  2619 	__BEGIN_INTERRUPTABLE__
  2621         __BEGIN_INTERRUPTABLE__
  2620 	do {
  2622         do {
  2621 	    n = sendto(sock, cp, nBytes, _flags, saPtr, alen);
  2623             n = sendto(sock, cp, nBytes, _flags, saPtr, alen);
  2622 	} while ((n < 0) && (errno == EINTR));
  2624         } while ((n < 0) && (errno == EINTR));
  2623 	__END_INTERRUPTABLE__
  2625         __END_INTERRUPTABLE__
  2624 
  2626 
  2625 	if (n < 0) {
  2627         if (n < 0) {
  2626 	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
  2628             __INST(lastErrorNumber) = __MKSMALLINT(errno);
  2627 	}
  2629         }
  2628 	RETURN (__MKSMALLINT(n));
  2630         RETURN (__MKSMALLINT(n));
  2629     }
  2631     }
  2630 #endif
  2632 #endif
  2631 bad: ;
  2633 bad: ;
  2632 %}.
  2634 %}.
  2633     "
  2635     "
  4761 ! !
  4763 ! !
  4762 
  4764 
  4763 !Socket class methodsFor:'documentation'!
  4765 !Socket class methodsFor:'documentation'!
  4764 
  4766 
  4765 version
  4767 version
  4766     ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.146 2000-03-24 12:50:17 cg Exp $'
  4768     ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.147 2000-05-08 13:57:42 cg Exp $'
  4767 ! !
  4769 ! !